UserID应该唯一吧? select (select count(*) from [Users] where UserID<= a.UserID) as [(自增列)], UserName,Address,Sex from [Users] a order by UserID
--可以用下面的方法来生成你要的结果 --但数据多时,效率低,数据多时,还是建议用临时表select UserID=(select count(*) from Users where UserID<=a.UserID) ,UserName,Address,Sex from Users a
如果只查询部分符合条件的:select (select count(*) from [Users] where 条件 and UserID<= a.UserID) as [(自增列)], UserName,Address,Sex from [Users] a where 条件 order by UserID
不好意思看错了,上面的pengda1li是对的
不是pengda1li 是 pengda1i呵呵
select identity(int,1,1),username,address,sex into newtable from users select * from newtalbe
select (select count(*) from [Users] where UserID<= a.UserID) as [(自增列)],
UserName,Address,Sex
from [Users] a
order by UserID
--但数据多时,效率低,数据多时,还是建议用临时表select UserID=(select count(*) from Users where UserID<=a.UserID)
,UserName,Address,Sex
from Users a
UserName,Address,Sex
from [Users] a
where 条件
order by UserID
是 pengda1i呵呵
select * from newtalbe