问题描述
我无法为 SSRS 中的单元格提供值,该值应该是不同值的总和.我有一个类似于以下屏幕截图的 SSRS 报告:
I'm having trouble coming up with a value for a cell in SSRS, which should be a sum of distinct values. I have a SSRS report that looks similar to the below screenshot:
我无法获取红色值(11.25 美元).我基本上需要根据不同的 Tracking #s 来计算 Ship Cost 的总和.所以有两个不同的跟踪#,一个的运输成本为 5.25 美元,另一个为 6.00 美元,所以以红色显示的总数应该是 11.25 美元.但我无法在 SSRS 中实现这一点,也无法在 SQL 查询中弄清楚.
I'm having trouble getting the value in red ($11.25). I basically need to sum the Ship Cost, based on distinct Tracking #s. So there are two distinct tracking #s, one with a Ship Cost of $5.25 and the other $6.00, so the total displayed in red should be $11.25. But I cannot achieve this in SSRS and can't figure it out in the SQL query either.
我正在考虑类似的子查询(并且我知道以下不是有效的 SQL):
I'm thinking a subquery like (and I know the below is not valid SQL):
(SELECT SUM([Ship Cost]) WHERE [Tracking #] IS DISTINCT) AS [Ship Cost]
但是我不知道怎么写.
推荐答案
先获取distinct list...
Get the distinct list first...
SELECT SUM(SQ.COST)
FROM
(SELECT DISTINCT [Tracking #] as TRACK,[Ship Cost] as COST FROM YourTable) SQ
这篇关于尝试对不同的值求和 SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!