正在为你努力加载中........

点滴记录 分享
17
2013-7
首页 >> mysql >> mysql case when查询

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

结果如下:

点击查看原图

一种更简单的写法:

 

select mydate ,sum(`status` = 0) as success_num ,count(*) as all_num from `data` GROUP BY mydate


作者:一根烟的寂寞 分类:mysql
浏览:88305 评论:0

发表评论: