题解 | #统计每种性别的人数#
统计每种性别的人数
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)
③对性别进行分组