题解 | #统计每种性别的人数#
统计每个学校的答过题的用户的平均答题数
http://www.nowcoder.com/practice/88aa923a9a674253b861a8fa56bac8e5
解法1: case when 对 profile 字段使用 like 区分情况
select case when profile like '%,female' then 'female' when profile like '%,male' then 'male' end as gender, count(*) from user_submit group by gender
解法2:使用 SUBSTRING_INDEX 对profile 进行拆分
select SUBSTRING_INDEX(profile,',',-1) as gender, count(*) from user_submit group by gender
解法3:使用 REGEXP_SUBSTR 对profile 进行拆分
select REGEXP_SUBSTR(profile,'[^,]+',1,4) as gender, count(*) from user_submit group by gender