日期:2014-05-17 浏览次数:20838 次
if object_id('[TB]') is not null drop table [TB]
go
create table [TB] (col1 int,col2 int)
insert into [TB]
select 0,4544 union all
select 5,8 union all
select 9,465 union all
select 782,5555 union all
select 548,858
select * from [TB]
SELECT CASE WHEN col1 = 0 THEN 0 ELSE num-1 END AS col1,col2 FROM (
SELECT col1,ROW_NUMBER()OVER(ORDER BY col1 ASC) AS num,col2
FROM dbo.TB)T
/*
col1 col2
0 4544
1 8
2 465
3 858
4 5555*/