2014-12-04 77 views
-1

我具有以下表結構SQL查詢所需分組列

TicketID Status Duration 
----------------------------- 
1234   8  2 
1233   8  10 
1232   4  5 
1231   8  12 
1230   4  50 
  • 狀態8個封閉
  • 狀態4表示打開

它需要具有輸出在下面的辦法。請只做那些需要的。如果可能的話,我希望它在一個單一的SQL查詢。

請幫助我以下列方式生成輸出。

Row  Closed (sum) Open(Sum) 
--------------------------------- 
    1  24    55 
+2

_ 「請做需要FUL」 _吧?你有沒有試過任何東西? – 2014-12-04 09:04:40

回答

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 
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 
+0

謝謝,它一直在工作。 – 2014-12-04 10:00:11

+0

@SandipkTatva如果您認爲這有幫助,那麼將其標記爲答案 – 2014-12-04 10:23:30