请问sql2000,在视图里如何加一列自增列?

study2003 2011-11-01 03:34:19
rt
...全文
333 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
快溜 2011-11-01
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 study2003 的回复:]
先建个全局表, 再建视图,这要可以用自增吗
[/Quote]这是两码事吧,用row_number就行了,如果是2005以上版本的话
study2003 2011-11-01
  • 打赏
  • 举报
回复
先建个全局表, 再建视图,这要可以用自增吗
study2003 2011-11-01
  • 打赏
  • 举报
回复
rt dawugui
用表里有会出现重复
aa px
.00 1
500.00 2
30.00 3
1200.00 4
1200.00 4
1200.00 4
1200.00 4
xuam 2011-11-01
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 study2003 的回复:]
是在视图里,视图上不能这样用
[/Quote]
先建个全局表, 再建视图.
dawugui 2011-11-01
  • 打赏
  • 举报
回复
--sql 2000

select t.* , px = (select count(1) from tb where col < t.col) + 1 from tb t

--sql 2005

select t.* , px = row_number() over(order by col) from tb t
study2003 2011-11-01
  • 打赏
  • 举报
回复
是在视图里,视图上不能这样用
xuam 2011-11-01
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 fredrickhu 的回复:]
SQL code
select id=identity(int,1,1) ,* into #t from tb
[/Quote]

正解.
--小F-- 2011-11-01
  • 打赏
  • 举报
回复
select id=identity(int,1,1) ,* into #t from tb

34,594

社区成员

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

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