可否使select语句多加一列:0,1,2,3,4,5...

hainang1234 2005-12-28 02:01:57
可否使select语句多加一列:0,1,2,3,4,5...
加的这列从0开始一直递增。

原始需求:给t1加数据,数据从t2中来,t1中的某一列为顺序列,每加一些数据,这些数据的顺序都是0,1,2

谢谢。
...全文
144 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
hainang1234 2005-12-28
  • 打赏
  • 举报
回复
多谢各位大侠!
老本 2005-12-28
  • 打赏
  • 举报
回复
Oracle: Rownum.
SQL Server 中没有直接的伪列可用。
-狙击手- 2005-12-28
  • 打赏
  • 举报
回复
select rowid = identity(int,0,1) ,a.f2, a.f3, ... into #t from t2 where ...

insert into s1 select * from #t

drop table #t

看错了,要从0
-狙击手- 2005-12-28
  • 打赏
  • 举报
回复
select rowid = identity(int,1,1) ,a.f2, a.f3, ... into #t from t2 where ...

insert into s1 select * from #t

drop table #t
点点星灯 2005-12-28
  • 打赏
  • 举报
回复

select identity(int,0,1) as 'ID',a.f2, a.f3, ... into #t from tablename

select * from #t
子陌红尘 2005-12-28
  • 打赏
  • 举报
回复
用临时表:

select identity(int,0,1) as rowid,* into #t from t2
insert into t1 select * from #t
drop table #t

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧