题解 | #截取出年龄#
截取出年龄
http://www.nowcoder.com/practice/b8d8a87fe1fc415c96f355dc62bdd12f
1.获取年龄,需要从profile字段中获取; 2.截取包含年龄的字符串范围substring_index(profile,',',-2),通过逗号截取,-2代表从后往前到倒数第二个逗号的位置,返回的结果是27,male;再一次截取substring_index('27,male',',',1),截取到第一个逗号前,返回:27;前两步整合得到substring_index(substring_index(profile,',',-2),',',1) as age 3.统计有多少参赛者,聚合函数count(device_id); 4.统计每个年龄的参赛者,group by age select substring_index(SUBSTRING_INDEX(PROFILE,',',-2),',',1) as age, count(device_id) from user_submit group by age
查看11道真题和解析