[求助]关于oracle分组后组外排序的问题
只用查询语句实现:
DEPTNO ENAME SAL TOP3
---------- ---------- ---------- ----------
20 KING 5000 1
20 CLARK 2450 2
20 MILLER 1300 3
10 SCOTT 3000 1
10 FORD 3000 2
10 JONES 2975 3
30 BLAKE 2850 1
30 ALLEN 1600 2
30 TURNER 1500 3
按部门分组,部门内部的sal降序,部门间按每个部门sal最大值(粗体字)降序,该如何实现 ,请教各位高手!!谢谢!!
DEPTNO ENAME SAL TOP3
---------- ---------- ---------- ----------
20 KING 5000 1
20 CLARK 2450 2
20 MILLER 1300 3
10 SCOTT 3000 1
10 FORD 3000 2
10 JONES 2975 3
30 BLAKE 2850 1
30 ALLEN 1600 2
30 TURNER 1500 3
按部门分组,部门内部的sal降序,部门间按每个部门sal最大值(粗体字)降序,该如何实现 ,请教各位高手!!谢谢!!
------------------------------------------------------------------------------------------------------------------------------------------
回复:[求助]关于oracle分组后组外排序的问题
selelct t1.*
from (select DEPTNO ,ENAME ,SAL , row_number() over(partition by deptno order by sal desc) top3 from tableName) t1,
(select rownum seq,depno from (select deptno ,max(sal) from tablename group by depno order by max(sal) desc)) t2
where t1.deptno=t2.deptno order by t2.seq,t1.sal desc;
from (select DEPTNO ,ENAME ,SAL , row_number() over(partition by deptno order by sal desc) top3 from tableName) t1,
(select rownum seq,depno from (select deptno ,max(sal) from tablename group by depno order by max(sal) desc)) t2
where t1.deptno=t2.deptno order by t2.seq,t1.sal desc;
本文探讨了如何在Oracle数据库中实现复杂的分组排序需求。具体而言,如何按部门分组后,使部门内部薪资降序排列,并且部门间依据最高薪资进行降序排序。文章提供了一种使用子查询和窗口函数ROW_NUMBER()的方法来实现这一目标。
1114

被折叠的 条评论
为什么被折叠?



