从sql中检索总金额
以下查询有什么问题:
SELECT wbCode||yr, CAST(coalesce(Cons,0) AS FLOAT), wbCode
FROM Commodities
Where CCode in (2611,2513,2961) Group by wbCode||yr
例如,我希望上面的查询返回给定年份(USA1990)中每个 wbCode 的总和;但上面的代码并没有总结;它正在检索与以下内容相同的数据:
SELECT wbCode||yr, CAST(coalesce(Cons,0) AS FLOAT), wbCode
FROM Commodities
Where CCode in (2611) Group by wbCode||yr
SELECT wbCode||yr, CAST(coalesce(Cons,0) AS FLOAT), wbCode
FROM Commodities Where CCode in (2513,2961)
Group by wbCode||yr
如何求和?
非常感谢您的帮助。
What is the problem with the following query:
SELECT wbCode||yr, CAST(coalesce(Cons,0) AS FLOAT), wbCode
FROM Commodities
Where CCode in (2611,2513,2961) Group by wbCode||yr
I want the query above to return the sums for every wbCode in a given yr (USA1990), for example; but the code above is not summing up; it is retrieving the same data as:
SELECT wbCode||yr, CAST(coalesce(Cons,0) AS FLOAT), wbCode
FROM Commodities
Where CCode in (2611) Group by wbCode||yr
SELECT wbCode||yr, CAST(coalesce(Cons,0) AS FLOAT), wbCode
FROM Commodities Where CCode in (2513,2961)
Group by wbCode||yr
How can I get it to sum?
Thank you so much for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么
||
?只需将它们分别分组或者
Why
||
? Just group by them separatelyOr
为什么不使用
SUM
函数来汇总结果?Why aren't you using
SUM
function to aggregate results?这个怎么样:
How about this: