10**.[使用table:EMP]
依SAL列出各部门在各区间的人数
使用N个DECODE DEPTNO $3001-$9999 $2001-$3000 $1001-$2000 < $1000
---------- ----------- ----------- ----------- ----------
10 1 1 1 0
20 0 3 1 1
30 0 1 4 1
依SAL列出各部门在各区间的人数
使用N个DECODE DEPTNO $3001-$9999 $2001-$3000 $1001-$2000 < $1000
---------- ----------- ----------- ----------- ----------
10 1 1 1 0
20 0 3 1 1
30 0 1 4 1
解决方案 »
- oracle10.0安装完成之后一直不能正常登陆(急)
- 表的查询速度突然变慢了
- 跪求马士兵老师的oracle视频!
- utl_file.fopen中的三种打开模式a/r/w的问题
- sql loader SEQUENCE 问题
- 解决一个存储过程
- 统计如下数据的sql怎么写
- oracle rman备份的问题。
- 关于两表联合查询。急!急!急!急!急!在线等!谢谢!
- PL/SQL中数组类型和RECORD类型使用求助!
- ORACLE10G中sys密码忘记了怎么办??
- OracleJobScheduler××××服务,这个服务是用来干嘛的,我该如何除了用"net OracleJobScheduler×××× start“启动呢
SQL> select * from tbl; EMPNO ENAME SAL DEPTNO
--------------------------------------- ---------------------------------------- --------------------------------------- ---------------------------------------
7788 scott 3000 20
7902 ford 3000 20
7521 ward 1250 20
7654 martin 1250 20
7789 scott1 2000 20
7790 scott1 800 30
7791 scott1 1200 40
7792 scott1 2200 10
7793 scott1 3200 30
7794 scott1 4200 1010 rows selectedSQL>
SQL> select deptno,
2 sum(case when sal<1000 then 1 else 0 end) "<1000",
3 sum(case when sal>1000 and sal<2000 then 1 else 0 end) "1001-2000",
4 sum(case when sal>2000 and sal<3000 then 1 else 0 end) "2001-3000",
5 sum(case when sal>3000 and sal<9999 then 1 else 0 end) "3001-9999"
6 from tbl group by deptno order by deptno; DEPTNO <1000 1001-2000 2001-3000 3001-9999
--------------------------------------- ---------- ---------- ---------- ----------
10 0 0 1 1
20 0 2 0 0
30 1 0 0 1
40 0 1 0 0SQL>
sum(case when sal>3000 and sal<9999 then 1 else 0 end) "$3001-$9999",
sum(case when sal>2000 and sal<3000 then 1 else 0 end) "$2001-$3000",
sum(case when sal>1000 and sal<2000 then 1 else 0 end) "$1001-$2000",
sum(case when sal<1000 then 1 else 0 end) "<$1000"
from emp group by deptno order by deptno;