[英]SQL server report builder 3.0 dynamic grouping and sum
所以我想做一個報告,我想使用特定條件將行分組。 這就是我所擁有的
Code July,1 July,2 SC BF
20 5 2 1 6
21 4 1 4 1
31 4 7 9 2
35 5 1 6 0
我想做的是二十,三十等的總和
Code July,1 July,2 SC BF
20 5 2 1 6
21 4 1 4 1
2* 9 3 5 7
31 4 7 9 2
35 5 1 6 0
3* 9 8 15 2
或者可能
Code July,1 July,2 SC BF
20 5 2 1 6
21 4 1 4 1
2* 5 7
31 4 7 9 2
35 5 1 6 0
3* 15 2
先感謝您
處理此問題的一種方法是在SQL設置中,您可以將其分組。 在這種情況下,如果Code是整數,則可以除以10,它將把所有二十多歲的人與2組合在一起,並將三十多歲的人與3組合在一起:
create table #test
(
intValue int,
sumValue int
)
insert into #test
select 20, 9
union all select 21, 10
union all select 30, 1
union all select 31, 2
select * , round(intValue/10,0) as GroupByThis
from #test
select Code July,1 July,2 SC BF from tablename
union
select DISTINCT Code/10 , (select SUM (July,1) over (Code/10) from tablename where code=t.code)July,1 , (select SUM (July,2) over (Code/10) from tablename where code=t.code) July,2 , (select SUM (SC) over (Code/10) from tablename where code=t.code) SC, (select SUM (BF) over (Code/10) from tablename where code=t.code) BF from tablename t
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.