题解 | #查看不同年龄段的用户明细#

查看不同年龄段的用户明细

http://www.nowcoder.com/practice/ae44b2b78525417b8b2fc2075b557592

我把SQL 玩成了 excel,这样好吗,这样不好,所以还是要学会用case

SELECT device_id,gender,
if(IFNULL(age,0)=0,'其他',if(age<20,'20岁以下',if(age<=24,'20-24岁','25岁及以上'))) as ages
from user_profile 

case 解法

select  device_id,gender, case 
when age is null then '其他'
when age<20 then '20岁以下'
when age<=24 and age >=20 then '20-24岁'
else'25岁及以上' end  as ages
from user_profile 
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务