我有以下表结构
TicketID Status Duration
-----------------------------
1234 8 2
1233 8 10
1232 4 5
1231 8 12
1230 4 50
需要以下列方式输出。请只做那些需要的。如果可能的话,我想在单个SQL查询中使用它。
请帮我按以下方式输出。
Row Closed (sum) Open(Sum)
---------------------------------
1 24 55
答案 0 :(得分:0)
select 1 as row,
sum(case when status = 8 then 1 else 0 end) as closed,
sum(case when status = 4 then 1 else 0 end) as open
from your_table
答案 1 :(得分:0)
select
1 as Row,
sum(case when Status=8 then 1 else 0 end ) as Closed_Sum,
sum(case when Status=4 then 1 else 0 end ) as Open_Sum
from
Mytable