题解 | #统计每种性别的人数#

统计每种性别的人数

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

select substring_index(profile,',',-1) as gender , count(profile) as number from user_submit
group by gender

substring_index(字符串,'定位标志',第几个) :按分隔符截取字符串

解题思路:在profile中包含身高、体重、年龄和性别的信息,这些信息是用“,”隔开的,利用substring_index函数可以截取出性别的字符串。

①截取性别信息,并命名为gender:substring_index(profile,',',-1) as gender

②统计个数:count(profile)

③对性别进行分组

全部评论

相关推荐

03-04 22:09
已编辑
南昌大学 golang
西北上单:29届? 请你去三角洲猛攻
点赞 评论 收藏
分享
03-12 15:35
嘉应学院 Python
快说谢谢牛牛精灵:说不定就是下一个寒武纪!
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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