2011-05-30 97 views
0

我有這樣MySql的選擇查詢

id status 
1 Pass 
2 Fail 
3 Pass 

我怎麼能算總有一排排其中狀態爲「失敗」與他們的一個選擇查詢ID(S)由GROUP_CONCAT表。我試圖得到這樣的輸出

total group_concat(id) 
3  1,2,3 
1  2 

有什麼建議嗎?

回答

1

你需要聯合兩個單獨的查詢:

select status, 
     count(*) as num, 
     group_concat(id) as ids 
from tests as status_stats 
union all 
select null as status, 
     count(*) as num, 
     group_concat(id) as ids 
from tests as total_stats