日期:2014-05-17  浏览次数:20617 次

求一語句.谢谢~
以下为原始表格的格式:
列1 列2 列3
1 MTEP1209-0216S TEP12090292
1 MTEP1209-0216S TEP12090288
1 MTEP1209-0216S TEP12090290
2 MTEP1211-0013B TEP13010005
2 MTEP1211-0013B TEP12110060
3 MTSP1211-0030B TSP13040001
3 MTSP1211-0030B TSP12120002
3 MTSP1211-0030B TSP12110032
3 MTSP1211-0030B TSP12110030
如何增加一列为自增的列,如下
列1 列2 列3 列4
1 MTEP1209-0216S TEP12090292 1
1 MTEP1209-0216S TEP12090288 2
1 MTEP1209-0216S TEP12090290 3
2 MTEP1211-0013B TEP13010005 1
2 MTEP1211-0013B TEP12110060 2
3 MTSP1211-0030B TSP13040001 1
3 MTSP1211-0030B TSP12120002 2
3 MTSP1211-0030B TSP12110032 3
3 MTSP1211-0030B TSP12110030 4
请高手指教....

------解决方案--------------------
SQL code
select *,
        row_number() over(partition by 列1 order by 列2) as 行号
from table

------解决方案--------------------
SQL code
SELECT *,ROW_NUMBER() OVER(PARTITION BY 列2 ORDER BY 列2)列4 FROM TB

------解决方案--------------------
SQL code

select *, row_number() over(partition by 列1 order by 列2) as 行号
from table