我有一个 MS 查询,它选择两个不同记录的计数,然后执行计算以从另一个结果中减去一个结果并将结果显示为difference
.
见下文:
Ticketnumber | Createdon | Modifiedon |
00012121 | 16/03/2015 | 15/03/2015 |
00211335 | 10/03/2015 | 17/03/2015 |
SELECT ( SELECT COUNT(incidentbase.ticketnumber) AS val2
FROM IncidentBase
WHERE createdon >= GETDATE() - 7
) - ( SELECT COUNT(incidentbase.ticketnumber) AS val1
FROM incidentbase
WHERE modifiedon >= GETDATE() - 7
) AS difference
我想要的是将结果显示为单个值,具体取决于结果是正数还是负数,类似于:
WHEN difference => 0 then 1
WHEN difference =< 0 then 0
有人可以帮忙吗?