我有一个返回2列和多行的查询.我如何只返回一个非0或null的和值?
表" audit"是这样的:
parent_link integer;
dr smallint
amount decimal(18,2)
select parent_link, sum(case dr when 1 then amount else -amount end)
from audit where books = 3 group by parent_link
Run Code Online (Sandbox Code Playgroud)
我正在检查dr列中的值列中的值是否为1和0值.
此查询起作用并返回几千行,其中0表示总和结果,2表示总和中的值.我只想返回具有总和值的行.
任何帮助将非常感激.
用途having:
select parent_link, sum(case dr when 1 then amount else -amount end)
from audit
where books = 3
group by parent_link
having sum(case dr when 1 then amount else -amount end) <> 0
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20983 次 |
| 最近记录: |