oracle 中的有如下的表
EMPNO ENAME SAL deptno ------ ------ ---- ------
7900 JAMES 800
7902 FORD 1600 10
7934 MILLER 1700 20
1000 Mary 6000 30
7369 SMITH 2850 20
7499 ALLEN 3000 20
7521 WARD 2970 10
7566 JONES 3400 30
7654 MARTIN 2500 10
7698 BLAKE 1900 30
7782 CLARK 2200 20
7788 SCOTT 900 10
现要求统计每个部门工资排在前3位的员工,不包括总经理Mary,她的部门为空
我写的语句如下,但是却不能过滤掉含有Mary的那条记录. select e1.ename,e1.sal,e1.deptno from t_emp e1
where(select count(distinct e2.sal) from t_emp e2
where e1.deptno=e2.deptno and e1.deptno is not null and
e1.sal<e2.sal)
<3;
请各位大侠指教!
EMPNO ENAME SAL deptno ------ ------ ---- ------
7900 JAMES 800
7902 FORD 1600 10
7934 MILLER 1700 20
1000 Mary 6000 30
7369 SMITH 2850 20
7499 ALLEN 3000 20
7521 WARD 2970 10
7566 JONES 3400 30
7654 MARTIN 2500 10
7698 BLAKE 1900 30
7782 CLARK 2200 20
7788 SCOTT 900 10
现要求统计每个部门工资排在前3位的员工,不包括总经理Mary,她的部门为空
我写的语句如下,但是却不能过滤掉含有Mary的那条记录. select e1.ename,e1.sal,e1.deptno from t_emp e1
where(select count(distinct e2.sal) from t_emp e2
where e1.deptno=e2.deptno and e1.deptno is not null and
e1.sal<e2.sal)
<3;
请各位大侠指教!
解决方案 »
- 求解决 ora-02778 name giver for the log directory is invaild
- 一个很菜的问题。在一个事务内, 有没有可能 不 读取,已经更新但还没有提交的数据
- oracle 10G有关存储规划的问题
- 一个select语句来实现
- 表连接问题
- 请大家帮助一下
- 在Oracle中删除某条记录时怎样用触发器实现主键(为编号)大于删除的这条所有的编号怎样减1
- 有什么办法将多个查询结果合并到一起!sql,decode
- 如何制作ORACLE客户端的安装程序
- 在redhat7.2下内核不同对oracle8i有什么影响?LD_ASSUME_KERNEL设置不同,为什么会产生不同结果
- ORACLE数据库需要手动启动?服务器重新启动后不会自动启动吗?
- 一个奇怪的查询现象,高手请进
where(select count(distinct e2.sal) from biao e2
where e1.deptno=e2.deptno and e1.deptno is not null and
e1.sal<e2.sal)
<3 and e1.deptno is not null;
FROM (SELECT *,
row_number() over(PARTITION BY deptno ORDER BY sal DESC) AS rn
FROM t_emp
WHERE deptno IS NOT NULL)
WHERE rn <= 3
ORDER BY deptno, rn
where (select count(distinct e2.sal) from t_emp e2
where e1.deptno=e2.deptno and e2.deptno is not null and
e1.sal<e2.sal) <3 and e1.deptno is not null;