我曾经面试过这样一个问题
来源:互联网 发布:qq视频变声软件 编辑:程序博客网 时间:2024/04/27 05:52
浦发大佬曾问我一个问题,一个表只有成绩和姓名,要求统计出各分数段的总人数:这个sql 当时没写出来
现补上:
select case when sal between 0 and 1500 then '10-20'
when sal between 1500 and 3000 then '21-30'
else '81-100' end, count(0) 人数
from emp
group by case when sal between 0 and 1500 then '10-20'
when sal between 1500 and 3000 then '21-30'
else '81-100' end
order by count(0)
还有个方式:比较两个写法 上面一个语句的order by 可以不要!!
SELECT (case when sal >= 0 and sal < 1500 then '10-20'
when sal >= 1500 and sal < 3000 then '20-30'
else 'other' end) as cases, count(1) as "人数"
from emp
WHERE sal >= 900 and sal < 8000
GROUP BY (case when sal >= 0 and sal < 1500 then '10-20'
when sal >= 1500 and sal < 3000 then '20-30'
else 'other' end);
select case
when sal >= 0 and sal < 1500 then
'[0,1500)'
when sal >= 1500 and sal < 3000 then
'[1500,3000)'
else
'[other)'
end sal_ranges,
count(0)
from emp
group by case
when sal >= 0 and sal < 1500 then
'[0,1500)'
when sal >= 1500 and sal < 3000 then
'[1500,3000)'
else
'[other)'
end;
- 我曾经面试过这样一个问题
- 曾经这样爱过你
- 曾经这样爱过你
- 我曾经来过
- 曾经我爱过
- 曾经做过一个让我有点自豪的项目
- 作为一个面试官,我会这样问问题——面试攻略之见招拆招
- 当你输入一个网址的时候,实际会发生什么?(赛门铁克电话面试我,曾经问过这个问题,最后一问,我只能说不知道)
- 世界上曾经有过这样一个中国
- 你是不是曾经也这样过?
- 我曾经爱过你
- 我曾经爱过你
- 谢谢你曾经爱过我
- 我曾经爱过你
- 我碰到过的面试问题
- 解决曾经让我郁闷的一个问题
- BAT招聘PHP程序员,曾经问过的10个PHP面试问题
- 谈下我曾经做过的一个心理健康管理系统
- UINavigationController和UITabBarController合用[转载比较好理解]
- Sensor信号输出YUV、RGB、RAW DATA、JPEG 4种方式区别
- Unity design patterns and concepts, looking for good sources
- Payment Terms 付款条件
- C++12.2 隐含的this指针(不懂)、mutable数据成员
- 我曾经面试过这样一个问题
- 今日之谬言,不谦谓悟道
- 灰度图转伪彩色图
- 快捷键让SublimeText在编文件快速在浏览器打开
- Google I/O 2013:Volley 图片缓存教程
- Sublime Text 3 安装Package Control官方教程
- 黑马day04 凤姐艺妓录&防盗链
- 从assets中把zip资源包复制到SD卡中
- 他山之石