怎么样给,有相同列的 数据添加一个递增的编号

表a,里面没有标识列 里面有字段user,id............,不清楚你说的到底有没有id列,你的具体表结构不清楚,下面做几个假设:

1、表中有自增列row:

select (select count(*) from table1 where [user]=t1.[user] and row>=t1.row) as id,[user] from table1 as t1

order by [user],id

2、表中没有自增列,但有其它列,其中有一列可以区分开每一行数据,假设为utime

select (select count(*) from table1 where [user]=t1.[user] and utime>=t1.utime) as id,[user] from table1 as t1

order by [user],id

3、如果上面的都没有,就要利用临时表了,先把表中的数据存到临时表table1(临时表带自增列row),然后按1中的方法查询。

猜你喜欢

转载自see-you-again.iteye.com/blog/2279096
今日推荐