读书人

select 的时候怎么生成自动增长列`

发布时间: 2012-03-04 11:13:34 作者: rapoo

select 的时候如何生成自动增长列``??
比如:
select myID=在这怎么写能生成自动ID ,* from a

[解决办法]
select myID=Row_Number() over(order by myID) from Table
不知道是不是你要的结果~
[解决办法]

  SELECT myID= (SELECT COUNT(编号) FROM 表1 AS T1
   WHERE T1.编号<= T2.编号),
   编号,名称
  FROM 表2 AS T2ORDER BY 1;
  GO
[解决办法]

SQL code
use pubsgoselect   ID=identity(int,   1,   1), * into #t  from titles   select   *   from   #t   drop   table   #t
[解决办法]
不懂
[解决办法]
identity(int,1,1)+临时表
[解决办法]
@@identity(int, 1, 1),
[解决办法]
select myID=(select count(列名) from 表名 as a where a.列名<b.列名),列名 from 表名 as b

可以吧
[解决办法]
什么数据库啊。楼上的回复至少ORACLE和SQL SERVER的都给你回答过了。
[解决办法]
探讨

  SELECT myID= (SELECT COUNT(编号) FROM 表1 AS T1
   WHERE T1.编号 <= T2.编号),
   编号,名称
  FROM 表2 AS T2 ORDER BY 1;
  GO

[解决办法]
select myID=identity(int, 1, 1), c.* into #t from
(
select 姓名=aname,支出钱=amoney,收入钱='',时间=atime from a union all select bname,支出钱='',收入钱=bmoney,时间=btime from b order by 时间
) c
select * from #t
drop table #t

[解决办法]
探讨

我想让两个连接的表select出来的时候,就有一个自动增长的列,如下:


SQL code
select 姓名=aname,支出钱=amoney,收入钱='',时间=atime from a union all select bname,支出钱='',收入钱=bmoney,时间=btime from b order by 时间

读书人网 >asp.net

热点推荐