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

统计每种性别的人数

http://www.nowcoder.com/practice/f04189f92f8d4f6fa0f383d413af7cb8

case语句+模糊查询=笨蛋题解! 了解case语句语法和模糊查询规则即可! select case when profile like '%,male' then 'male' when profile like '%,female' then 'female' end gender,count(device_id) from user_submit group by gender;

全部评论
female这个字母中也包含'male',为了无歧义所以才加的吧
16 回复 分享
发布于 2022-02-28 19:24
我觉得很有道理,可是为什么说我们是笨蛋
12 回复 分享
发布于 2022-04-20 14:39
这里可以直接like %female 就可以了
3 回复 分享
发布于 2022-03-11 17:42
这里%后面为什么要接一个逗号
2 回复 分享
发布于 2021-11-12 14:38
为什么要用两个when,而用when... else 会报错呢?
1 回复 分享
发布于 2023-02-01 17:05 上海
很好的思路,我想的是用substring 去慢慢截取,虽然是成了,但有bug,这个才是笨蛋想法233 select substring(profile,15) gender, count(device_id) number from user_submit group by substring(profile,15)
1 回复 分享
发布于 2022-10-28 10:29 江苏
写得时候先写的%female 再是male,这样查出来的结果也是对的,但是先like %male 就不对了。是不是说明sql case when 语句也有先后顺序
1 回复 分享
发布于 2022-04-22 21:25
想到要这种方法,但是逗号挺巧妙
点赞 回复 分享
发布于 2024-01-01 17:05 湖南
好的我承认我是笨蛋
点赞 回复 分享
发布于 2023-10-16 14:35 北京
select case when profile like '%female' then 'female' else 'male' end as gender,count(device_id) as number from user_submit group by gender
点赞 回复 分享
发布于 2023-03-07 13:46 陕西
好的,我是笨蛋
点赞 回复 分享
发布于 2023-01-19 15:20 浙江
嘤嘤嘤
点赞 回复 分享
发布于 2022-07-23 10:49
为啥是笨蛋题解呢 select case when profile like "%,male%" then "male" else "female" END gender,count(*) number from user_submit group by gender
点赞 回复 分享
发布于 2022-07-11 16:11
ni wei sheng me ma wo men shi ben dan ne ?
点赞 回复 分享
发布于 2022-07-05 00:33

相关推荐

仁者伍敌:牛子这些人还会点一个自动回复,boss都不带回复的
点赞 评论 收藏
分享
真烦好烦真烦:豆包润色了自己没看看吗,再说了,都说豆包是愚蠢且勤快的大学生,ds才是聪明的研究生,怎么敢让豆包写论文的
你们的毕业论文什么进度了
点赞 评论 收藏
分享
评论
277
11
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务