我需要编写一份关于 3 个不同状态值的摘要报告,每个状态都有一个计数和一个金额列,结果显示在一个表中。例如,输出将如下所示:
生成每一行代码(在单独的输出中)的查询是:
select case when status_key = '2' then 'Paid' else '' end as 'Status'
, COUNT(BillNo) as [Count]
, SUM(amtpd) as [Amount Paid]
from billtable
where client = 101
and status_key = '2'
group by status_key
select case when status_key = '1' then 'Queued' else '' end as 'Status'
, COUNT(BillNo) as [Count]
, SUM(amtpd) as [Amount Paid]
from billtable
where client = 101
and status_key = '1'
group by status_key
select case when status_key = '4' then 'Hold' else '' end as 'Status'
, COUNT(BillNo) as [Count]
, SUM(amtpd) as [Amount Paid]
from billtable
where client = 101
and status_key = '4'
group by status_key
这会产生三个结果,例如:
我正在使用 SQL Server 数据库和 SSMS 来开发查询。