题解 | #截取出年龄#

截取出年龄

https://www.nowcoder.com/practice/b8d8a87fe1fc415c96f355dc62bdd12f

/*select left(substring_index(profile,',',-2),2) age,count(device_id) number
from user_submit
group by age*/
select substring_index(substring_index(profile,',',-2),',',1) age,count(device_id) number
from user_submit
group by age

笔记:left(字符串,字符串长度),left(study,2):取study这个字符串的前两位

这里准备使用left函数,但是在实际业务中有些人注册年龄会乱选,有可能有错误值个位数和3位数,虽然题中都是两位数,可以使用left长度取2,为了严谨,选择使用两个substring套用

全部评论

相关推荐

07-24 16:39
已编辑
门头沟学院 测试开发
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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