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