码迷,mamicode.com
首页 > 其他好文 > 详细

case when then用法

时间:2016-10-30 16:44:13      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:dev   and   concat   别名   strong   设备   日期   cas   span   

--简单Case函数 
CASE sex 
         WHEN ‘1‘ THEN ‘男‘ 
         WHEN ‘2‘ THEN ‘女‘ 
ELSE ‘其他‘ END 



//案例
select cid as 渠道编号, case cid when ‘3‘ then ‘华为‘ when ‘20645‘ then ‘小米‘ else cid end as 渠道名称, //别名 渠道名称,遇见3表示华为渠道,遇到20645表示小米渠道 intdate as 注册日期, install as 激活人数, reg2 as 注册人数, concat( left(reg2 / install *100, 5), ‘%‘) as 注册率, ip as 去重IP数, device as 去重设备数, charge_user as 充值人数, charge_times as 充值次数, charge_money as 充值面额, charge_money2 as 新增充值面额, concat( left(day1 / reg2 *100, 5), ‘%‘) as 次日留存率, concat( left(day2 / reg2 *100, 5), ‘%‘) as 2日留存率, concat( left(day3/ reg2 *100, 5), ‘%‘) as 3日留存率, concat( left(day4 / reg2 *100, 5), ‘%‘) as 4日留存率, concat( left(day5 / reg2 *100, 5), ‘%‘) as 5日留存率, concat( left(day6 / reg2 *100, 5), ‘%‘) as 6日留存率, concat( left(day7 / reg2 *100, 5), ‘%‘) as 7日留存率 from union_data where intdate>= ‘20161020‘ and intdate<= ‘20161031‘

 

case when then用法

标签:dev   and   concat   别名   strong   设备   日期   cas   span   

原文地址:http://www.cnblogs.com/dengyg200891/p/6013286.html

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