题解 | #统计每种性别的人数#
统计每种性别的人数
https://www.nowcoder.com/practice/f04189f92f8d4f6fa0f383d413af7cb8
select 'male' , count(sub.male) from (select SUBSTRING_INDEX(profile,',',-1) as male from user_submit) sub where sub.male = 'male' union all select 'female' , count(sub.male) from (select SUBSTRING_INDEX(profile,',',-1) as male from user_submit) sub where sub.male = 'female'
首先分析这个输出格式 得知female和male要分别输出 ,然后题意肯定要用到sql分割语句 所以使用子查询就能查出来