ORACLE 排序函数row_number / rank / dense_rank

ORACLE 排序函数row_number / rank / dense_rank


ORACLE 排序函数row_number / rank / dense_rank_第1张图片

WITH A AS(
SELECT '语文'  AS CUR,
       88      AS FS
  FROM DUAL
 UNION ALL
SELECT '数学'  AS CUR,
       88      AS FS
  FROM DUAL
 UNION ALL
SELECT '英语'  AS CUR,
       63      AS FS
  FROM DUAL
 UNION ALL
SELECT '物理'  AS CUR,
       90      AS FS
  FROM DUAL
)
SELECT CUR   AS 课程,
       FS    AS 分数,
       ROW_NUMBER() OVER(ORDER BY FS DESC)  AS 排名_ROW_NUMBER,     --顺序排名,有相同数值的时候,排名不重复
       RANK()       OVER(ORDER BY FS DESC)  AS 排名_RANK,           --跨数排名,有相同数值的时候,排名重复  
       DENSE_RANK() OVER(ORDER BY FS DESC)  AS 排名_DENSE_RANK      --紧凑排名,有相同数值的时候,排名重复   (DENSE 有密集的意思,可以以此记忆)
  FROM A

你可能感兴趣的:(数据库开发,oracle)