码迷,mamicode.com
首页 > 数据库 > 详细

case when then else end mysql

时间:2015-05-05 16:22:02      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

select (@rownum:=@rownum+1) AS serial_Num, tb_ser.name as server_Name, count(tb_uer.id) as regist_Num  ,

count(case when tb_uer.status=0 then tb_uer.id else null end) as no_Active,

count(case when date_format(tb_uer.lastLoginTime,‘%Y-%m-%d‘)= @con1 then tb_uer.id else null end) as  active_Num,

count(tb_uer.id)-count(case when date_format(tb_uer.lastLoginTime,‘%Y-%m-%d‘)=@con1 then tb_uer.id else null end) as no_Active_Num

from p_service_branch tb_ser left join 

p_cuser tb_uer on tb_uer.serviceId=tb_ser.id 

,(SELECT @rownum:=0) rownumber where 1=1  @con2  @con3  group by tb_ser.id

case when then else end mysql

标签:

原文地址:http://www.cnblogs.com/xwchengc/p/4479180.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!