case when then用法
--简单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'
无语言基础,自学python所做的各种笔记,欢迎大牛指点.