mysql case when查詢

select mydate,
CASE
    when `status` = 0 then count(*)
		else '0'
END success_num,
CASE
    when `status` >=0 then count(*)
		else '0'
END all_num
from `data`  group by mydate

結果以下:sql

點擊查看原圖

一種更簡單的寫法:3d

 

select mydate ,sum(`status` = 0) as success_num ,count(*) as all_num from `data` GROUP BY mydate
相關文章
相關標籤/搜索