[求助]关于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中实现复杂的分组排序需求,即先按部门分组,然后在每个部门内按薪资降序排列,并且部门之间再按照最高薪资进行降序排列。提供了具体的SQL实现方案。
1114

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



