我如何使用排名功能来解决这个问题?
How can I use rank function to solve this?
我有这个数据:
我想要这个结果:
所以我试过了:
SELECT
text_area,
ordered_area,
RANK () OVER (ORDER BY text_area) ranked_area
FROM
(
SELECT '1200 AA' text_area ,1 ordered_area
FROM
DUAL
UNION ALL
SELECT '1200 AA' ,2
FROM
DUAL
UNION ALL
SELECT '1200 BB' ,3
FROM
DUAL
UNION ALL
SELECT '1200 CC' ,4
FROM
DUAL
UNION ALL
SELECT '1200 CC' ,5
FROM
DUAL
)
但是并没有解决我的问题。我该如何解决这个问题?
提前致谢
DENSE_RANK 不是排名:
SELECT
text_area,
ordered_area,
DENSE_RANK () OVER (ORDER BY text_area) ranked_area
FROM
(
SELECT '1200 AA' text_area ,1 ordered_area
FROM
DUAL
UNION ALL
SELECT '1200 AA' ,2
FROM
DUAL
UNION ALL
SELECT '1200 BB' ,3
FROM
DUAL
UNION ALL
SELECT '1200 CC' ,4
FROM
DUAL
UNION ALL
SELECT '1200 CC' ,5
FROM
DUAL
)
如果你想在你的排名中避免"gaps",你应该使用dense_rank
而不是rank
:
DENSE_RANK () OVER (ORDER BY text_area) ranked_area
我有这个数据:
我想要这个结果:
所以我试过了:
SELECT
text_area,
ordered_area,
RANK () OVER (ORDER BY text_area) ranked_area
FROM
(
SELECT '1200 AA' text_area ,1 ordered_area
FROM
DUAL
UNION ALL
SELECT '1200 AA' ,2
FROM
DUAL
UNION ALL
SELECT '1200 BB' ,3
FROM
DUAL
UNION ALL
SELECT '1200 CC' ,4
FROM
DUAL
UNION ALL
SELECT '1200 CC' ,5
FROM
DUAL
)
但是并没有解决我的问题。我该如何解决这个问题?
提前致谢
DENSE_RANK 不是排名:
SELECT
text_area,
ordered_area,
DENSE_RANK () OVER (ORDER BY text_area) ranked_area
FROM
(
SELECT '1200 AA' text_area ,1 ordered_area
FROM
DUAL
UNION ALL
SELECT '1200 AA' ,2
FROM
DUAL
UNION ALL
SELECT '1200 BB' ,3
FROM
DUAL
UNION ALL
SELECT '1200 CC' ,4
FROM
DUAL
UNION ALL
SELECT '1200 CC' ,5
FROM
DUAL
)
如果你想在你的排名中避免"gaps",你应该使用dense_rank
而不是rank
:
DENSE_RANK () OVER (ORDER BY text_area) ranked_area