Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如果行数据相同,则将数字增加1_Sql - Fatal编程技术网

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

你的数据库管理系统是什么?你的数据库管理系统是什么?