首页 > 编程学习 > mysql练习--统计每种性别的人数

mysql练习--统计每种性别的人数

发布时间:2022/9/23 2:58:44

描述

题目:现在运营举办了一场比赛,收到了一些参赛申请,表数据记录形式如下所示,现在运营想要统计每个性别的用户分别有多少参赛者,请取出相应结果
 
示例:user_submit
device_id profile blog_url
2138 180cm,75kg,27,male http:/url/bigboy777
3214 165cm,45kg,26,female http:/url/kittycc
6543 178cm,65kg,25,male http:/url/tiger
4321 171cm,55kg,23,female http:/url/uhksd
2131 168cm,45kg,22,female http:/urlsydney
 
根据示例,你的查询应返回以下结果:
gender number
male 2
female 3

select if(profile like "%female","female","male")gender, count(*) as number
from user_submit
group by gender
select
 case when profile like "%,male" then 'male'
 when profile like "%,female" then 'female'
 end gender,count(*)number
 from user_submit
 group by gender
select substring_index(profile,',',-1)gender,count(*)number
from user_submit
group by gender

 

Copyright © 2010-2022 mfbz.cn 版权所有 |关于我们| 联系方式|豫ICP备15888888号