如何在 sql 服务器中使用 sql 查询和/或表达式 return 总计的单行

How to return a single row with a total using a sql query and or expressions in sql server

我有一个查询已写入 return 所有付款。发生的事情是,当我 运行 我的报告时,它是 returnng 多行而不是一行,我认为这是因为我在查询中有 groupby 子句。 问题是我似乎需要分组依据,因为一些字段包含在我的数据集中,例如我实际上使用交易日期进行过滤,所以我不能忽略它。这是我下面的查询

select distinct Transaction_Amount, Transaction_Type, Transaction_Date  --'R '+ CONVERT(varchar,SUM(Transaction_Amount)) as [Epurse Credits/Deposits]
from Transactional_Account
where Transaction_Type like '%credit%'

即使我将表达式设为 =SUM(Fields!Transaction_Amount.Value,"DataSet1"),结果集仍然包含多行

无需在数据集查询中包含总数。只需在报表设计中向您的 table/matrix 添加一个行组(或更改现有的 'details' 行组),然后按您需要显示的所有公共字段进行分组。

如果您希望每笔交易一行,则删除 DISTINCT 并使用聚合函数:

select max(Transaction_Amount), max(Transaction_Type), max(Transaction_Date)
      sum(Transaction_Amount) as [Epurse Credits/Deposits]
from Transactional_Account
where Transaction_Type like '%credit%';

这 returns 其他各列的任意(嗯,最大值)值。但是保证你排一排。