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

统计每种性别的人数

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

相关推荐

05-12 17:00
门头沟学院 Java
king122:你的项目描述至少要分点呀,要实习的话,你的描述可以使用什么技术,实现了什么难点,达成了哪些数字指标,这个数字指标尽量是真实的,这样面试应该会多很多,就这样自己包装一下,包装不好可以找我,我有几个大厂最近做过的实习项目也可以包装一下
点赞 评论 收藏
分享
06-10 23:36
已编辑
首都经济贸易大学 C++
点赞 评论 收藏
分享
07-01 17:14
中北大学 Java
兄弟们是真是假
牛客46374834...:我在boss上投java岗从来没成功过
点赞 评论 收藏
分享
评论
277
11
分享

创作者周榜

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