日期:2014-05-17 浏览次数:20631 次
--查询
--sql 2000
select 图二 = (select count(1) from tb where 排序 = t.排序 and 图一 < t.图一) + 1 , 排序 from tb t
select 图二 = (select count(1) from tb where 图一 < t.图一) + 1 , 排序 from tb t
--sql 2005
select 图二 = row_number() over(partition by 排序 order by 图一), 排序 from tb t
select 图二 = row_number() over(order by 图一), 排序 from tb t
--更改
update tb
set 图二 = (select count(1) from tb where 排序 = t.排序 and 图一 < t.图一) + 1 , 排序 from tb t
if not object_id('tb') is null
drop table tb
Go
Create table tb([ID] int,[name] nvarchar(2))
Insert tb
select 1,N'设置' union all
select 4,N'设置' union all
select 8,N'设置' union all
select 12,N'设置'
Go
--2000
Select ID=(select count(*) from tb where id<=t.id),
[Name]
from tb t
---2005
select ID=row_number()over(order by id ),
[name]
from tb
if object_id('tb')>0
drop table tb
create table tb(id int,s