SQL语句面试题
答案:2 悬赏:50 手机版
解决时间 2021-02-17 19:02
- 提问者网友:泪痣哥哥
- 2021-02-16 22:48
SQL语句面试题
最佳答案
- 五星知识达人网友:纵马山川剑自提
- 2021-02-16 23:23
select a.user_job as "职业",b.man_num as "男性人数",c.woman_num as "女性人数",count(id) as "总人数" from user a left join (select user_job,count(id) as man_num from user where user_sex=1 group by user_job) b on a.user_job=b.user_job left join (select user_job,count(id) as woman_num from user where user_sex=0 group by user_job) c on a.user_job=c.user_job group by a.user_job
这样写试一下,看看是否好用。
这样写试一下,看看是否好用。
全部回答
- 1楼网友:话散在刀尖上
- 2021-02-17 00:39
select user_job as 职业,sum(case when user_sex=0 then 1 else 0 end) as 女性人数,
sum(case when user_sex=1 then 1 else 0 end) as 男性人数,count(*)as 总人数 from user
group by user_job;
sum(case when user_sex=1 then 1 else 0 end) as 男性人数,count(*)as 总人数 from user
group by user_job;
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯