SQL入门题解 | #截取出年龄#
截取出年龄
https://www.nowcoder.com/practice/b8d8a87fe1fc415c96f355dc62bdd12f
/*1
substring_index(str,delim,count)
str:要处理的字符串
delim:分隔符
count:计数
如果count是正数,那么就是从左往右数,第N个分隔符的左边的全部内容
如果count是负数,那么就是从右往左数,第N个分隔符的右边的全部内容
如果需要中间内容,需要嵌套使用
注意:如果count为1(而不是0),表示从第一个位置开始【数据库的记录都是从1开始,没有从0开始】。*/
# substring_index 可以嵌套使用
select
# substring_index(profile,",",3) as age, 165cm,45kg,26 不对 是取3位置左边的
# substring_index(profile,",",-2) as age, #不对 27,male
substring_index(
substring_index(profile,',',-2),',',1
) as age ,
count(device_id) as number
from user_submit
group by age;
SQL错题 文章被收录于专栏
每天学习一遍 刷题刷题 越刷越强!
查看6道真题和解析

