请大家帮忙看看这道题怎么做有表T,该表只有一列i,该列i信息(数据)如下:  
1  
NULL  
2  
3  
8  
用SQL语句求如下的结果集(一列):  
0  
1  
2  
3  
4  
要求:使用一条语句得到结果(不得使用子查询)  

解决方案 »

  1.   

    declare @i int
    set @i=-1
    update t set i=@i,@i=@I+1
      

  2.   

    select ISNULL(c,0) from t order by ISNULL(c,0)
      

  3.   

    select case when ISNULL(c,0)=8 then 4 else ISNULL(c,0) end  from t order by case when ISNULL(c,0)=8 then 4 else ISNULL(c,0) end 
      

  4.   

    create table tb(id int)
    insert into tb values(1)  
    insert into tb values(NULL)  
    insert into tb values(2)
    insert into tb values(3) 
    insert into tb values(8)  
    go--查询
    select * , new_id = row_number() over(order by id) - 1 from tbdrop table tb/*
    id          new_id
    ----------- --------------------
    NULL        0
    1           1
    2           2
    3           3
    8           4(5 行受影响)
    */