Sql 如果行数据相同,则将数字增加1
我有一张有很多行的桌子。 表格的格式如下所示Sql 如果行数据相同,则将数字增加1,sql,Sql,我有一张有很多行的桌子。 表格的格式如下所示 col1|col2 --------- 001 |01| 001 |01| 001 |01| 001 |01| 001 |02| 001 |02| 001 |02| 001 |02| 001 |03| 001 |03| 001 |03| 002 |01| 002 |01| 002 |01|
col1|col2
---------
001 |01|
001 |01|
001 |01|
001 |01|
001 |02|
001 |02|
001 |02|
001 |02|
001 |03|
001 |03|
001 |03|
002 |01|
002 |01|
002 |01|
002 |01|
我想在表中添加一个新列,其中检查col1和col2的值,并在col3中插入新值
col1|col2|col3
---------------
001 |01 |1
001 |01 |2
001 |01 |3
001 |01 |4
001 |02 |1
001 |02 |2
001 |02 |3
001 |02 |4
001 |03 |1
001 |03 |2
001 |03 |3
002 |01 |1
002 |01 |2
002 |01 |3
002 |01 |4
使用支持大多数dbms的row\u number()
select *, row_number() over(partition by col1,col2 order by col2) as col3
from table_name
使用支持大多数dbms的row\u number()
select *, row_number() over(partition by col1,col2 order by col2) as col3
from table_name
你的数据库管理系统是什么?你的数据库管理系统是什么?