表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中的方法查询。

本文探讨了在SQL中为表中的记录分配唯一标识符的方法。通过三种不同情况的假设,包括存在自增列、存在区分行数据的列以及利用临时表的方法,详细介绍了如何为数据集生成递增ID。

141

被折叠的 条评论
为什么被折叠?



