关于row_number() over的问题 SELECT
a
,b
,c
,ROW_NUMBER() OVER (ORDER BY b, c, d, a) ROWNO
FROM
table
ORDER BY
a
,b
,c
,d;
如上,关于 ROW_NUMBER() OVER (ORDER BY...)有几个问题,求解答
1.ROW_NUMBER() 的order by是返回的是该字段在排序后的位置吗
2.在进行ROW_NUMBER() OVER操作时,和rownum有没有联系
3.ROW_NUMBER() 和rownum相比,效率如何 ------解决方案--------------------
row_number() over()和rownum最大的区别在于前者可以进行pratition by.
例如:
with t as
(select 1 id, 10 c1
from dual
union all
select 1 id, 20 c1
from dual
union all
select 2 id, 10 c1
from dual
union all
select 4 id, 10 c1
from dual
union all
select 4 id, 10 c1
from dual
union all
select 4 id, 10 c1
from dual)
select t.*, row_number() over(partition by id order by c1) from t;
其实这个才是row_number()over最大的作用 ------解决方案--------------------