高级函数-case
2024-10-01 11:52:22
case函数 (适合区间,>,<判断)
case when 判断表达式 then
when 判断表达式 then
.....
end
select deptno,count(*) total,
sum(case when sal>=2000 then 1
end) great,
sum(case when sal<2000 then 1
end) least
from emp
where deptno is not null
group by deptno;
//统计部门中男人数和女人数
create table j20(
id number(7),
name varchar(20),
sex char(1), --'M'或'F'
deptno number(7));
select deptno,
sum(decode(sex,'M',1,0)) as male,
sum(decode(sex,'F',1,0)) as female
from j20
group by deptno;
select deptno,
sum(case when sex='M' then 1
else 0 end) as male,
sum(case when sex='F' then 1
else 0 end) as female
from j20
group by deptno;
//基于EMP表查询部门编号,工资1000以内人数,
1000-2000人数,2000以上人数
select deptno,
sum(case when sal<1000 then 1
else 0
end) "1000以内",
sum(case when sal>=1000 and sal<2000 then 1
else 0
end) "1000-2000",
sum(case when sal>=2000 then 1
else 0
end) "2000以上"
from emp
group by deptno;
//查询调薪结果,规则:MANAGER涨10%,CLERK涨20%,
其他人涨5%
select empno,ename,job,sal,
decode(job,'MANAGER',sal*1.1,
'CLERK',sal*1.2,
sal*1.05) "加薪之后"
from emp;
最新文章
- createjs学习二之flash转canvas学习1
- python导入opencv解决no module named cv2问题
- JUC.Condition学习笔记[附详细源码解析]
- 那些年我们一起过的JS闭包,作用域,this,让我们一起划上完美的句号。
- 【LeetCode】389 Find the Difference(java)
- python编程关键字
- 【翻译十五】-java并发之固定对象与实例
- Java可变参数讲解
- C#基础--局部类型Partial
- 学习css3中的动画
- selenium+BeautifulSoup实现强大的爬虫功能
- 创建maven项目pom.xml第一行报错
- Vue-生命周期图示 注解
- c#Socket服务器与客户端的开发(1)
- erlang证书加密
- golang context
- Nancy.Net之旅-初次见面
- ApplicationListener详解
- PCLVisualizer可视化类
- 【前端开发工具】WijmoJS 2018 v3 正式发布,全面支持Angular7
热门文章
- volatile可见性和指令重排
- 02springMVC理解DispatcherServlet
- 网络抓包工具 Fiddler
- scikit-learn系列之如何存储和导入机器学习模型
- 利用flashback transaction query新特性进行事务撤销
- 解决:[WARNING] fpm_children_bury(), line 215: child 2736 (pool default) exited on signal 15 SIGTERM after 59.588363 seconds from start
- CLR - 设计类型
- iOS 内网内测应用发布
- pgpool中的配置参数的定义
- 订购一套Arduino UNO r3入门套件