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

统计每个学校的答过题的用户的平均答题数

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





全部评论

相关推荐

不愿透露姓名的神秘牛友
03-29 08:32
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务