简体   繁体   English

基于行号的 SSRS 总和值

[英]SSRS sum values based on row number

I would like to get the sum of all values in a column IF they have a rowNumber greater than the current row我想获得列中所有值的总和,如果它们的 rowNumber 大于当前行

so if i have 4 rows:所以如果我有 4 行:

Row 1 would be the sum of rows 2,3 and 4第 1 行将是第 2,3 行和第 4 行的总和

Row 2 would be the sum of rows 3 and 4第 2 行将是第 3 行和第 4 行的总和

Row 3 would be the value of row 4第 3 行将是第 4 行的值

Row 4 would be 0第 4 行将为 0

This is the query I currently have:这是我目前的查询:

SELECT
  no_,
  name AS member,
  amount,
  effective,
  balance

FROM c

WHERE 
    status != 'closed'
    AND amount != 0.00
ORDER BY no_, effective

In my ssrs table I'm using the expression RowNumber("member") to assign row numbers for each row per member在我的 ssrs 表中,我使用表达式 RowNumber("member") 为每个成员的每一行分配行号

You would seem to want a cumulative sum in reverse order, excluding the current value.您似乎希望以相反的顺序累积总和,不包括当前值。 I would express this as:我会表达为:

select sum(val) over (order by rownum desc) - val

I am clear how this relates to your query.我很清楚这与您的查询有何关系。

You can also express this using a window frame:您还可以使用窗口框架来表达这一点:

select sum(val) over (order by rownum rows between 1 following and unlimited following)

The only difference is that this would return NULL for the last row rather than 0 .唯一的区别是这将为最后一行返回NULL而不是0

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

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