数据
a|b|c
-----
1|1|2
1|1|2
1|2|3
2|2|2
希望取出格式如下
a|b|c|rw
---------
1|1|2|1
1|1|2|2
1|2|3|1
2|2|2|1
===============
用row_number按a分组能得出以下结果
a|b|c|rw
---------
1|1|2|1
1|1|2|2
1|2|3|3
2|2|2|1
但是不是我想要的,我需要按a,b,c分组
------解决方案--------------------
row_number()over(partition by a order by a,b,c)
------解决方案--------------------
- SQL code
select a , b, c, row_number() over(partition by a , b, c order by a , b, c) rw from tb
------解决方案--------------------
- SQL code
create table tb(a int,b int,c int)insert into tb values(1,1,2)insert into tb values(1,1,2)insert into tb values(1,2,3)insert into tb values(2,2,2)select a , b, c, row_number() over(partition by a , b, c order by a , b, c) rw from tb/* A B C RW--------------------------------------- --------------------------------------- --------------------------------------- ---------- 1 1 2 1 1 1 2 2 1 2 3 1 2 2 2 14 rows selected*/drop table tb
------解决方案--------------------
楼上正解!
------解决方案--------------------
- SQL code
--晕,没看到你最后一句话要按a,b,c分组row_number()over(partition by a,b,c order by a,b,c)
------解决方案--------------------
------解决方案--------------------
partition by下就可以了
------解决方案--------------------