sql查询要求在单行中分组列
我有以下表格结构sql查询要求在单行中分组列,sql,Sql,我有以下表格结构 TicketID Status Duration ----------------------------- 1234 8 2 1233 8 10 1232 4 5 1231 8 12 1230 4 50 状态8表示关闭 状态4意味着开放 它需要以以下方式输出。请做必要的事。如果可能的话,我希望它出现在
TicketID Status Duration
-----------------------------
1234 8 2
1233 8 10
1232 4 5
1231 8 12
1230 4 50
- 状态8表示关闭
- 状态4意味着开放
Row Closed (sum) Open(Sum)
---------------------------------
1 24 55
“请做必要的事”嗯?您尝试过什么吗?谢谢,它一直在工作。@SandipkTatva如果您认为这有帮助,请将其标记为答案
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
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