简体   繁体   English

SSRS 报告的 SQL Server 查询

[英]SQL Server query for SSRS report

I have a table like this:我有一张这样的表:

period    balance
-----------------
1         100
1         200
2         300
2         400  
3         400
3         500

I need to show this in a SSRS report;我需要在 SSRS 报告中显示这一点; I would like to calculate sum if max period as column maximum, then sum based on the second max which is 2如果最大周期为列最大值,我想计算总和,然后根据第二个最大值求和,即 2

3      2       1
-------------------
900    700     300

Thanks谢谢

I'm assuming you want to sort the periods by the sum value of each period?我假设您想按每个时期的总和值对时期进行排序?

If so, the easiest way is to simply sum your data by period.如果是这样,最简单的方法是简单地按时间段对数据求和。

SELECT period, SUM(balance) as periodBalance GROUP BY period

This will give you这会给你

period periodBalance
     1 300
     2 700
     3 900

Them in SSRS use a matrix and set the column group to group on period.它们在 SSRS 中使用矩阵并将列组设置为按周期分组。 finally set the column group sort to periodBalance ZA assuming you want to see the largest periodBalance first.最后将列组排序设置为 periodBalance ZA 假设您想首先查看最大的 periodBalance。 If you just want to see the periods in reverse order then just set the sort to period ZA如果您只想以相反的顺序查看期间,则只需将排序设置为期间 ZA

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM