簡體   English   中英

SQL Server報表生成器3.0動態分組和總和

[英]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

先感謝您

在ssrs報表中,您可以在數據集中添加一個計算字段,字段名稱為Group,表達式為=Floor(Fields!code.Value/10) ,然后在tablix中將總和累加到該分組上。 添加表達

創建Tablix

結果

處理此問題的一種方法是在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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM