select nvl(i,0) As i from tablename order by i
这个就能得到0,1,2,3,8
没有nvl函数用select (case when i is null then 0 else i end) As i from tablename order by i
结果都是0,1,2,3,8

解决方案 »

  1.   

    select isnull(i, 0) as i_sorted from T order by i_sorted asc
      

  2.   

    select case when isnull(i,0)>4 then 4 else isnull(i,0) end
    from T
    order by 1
      

  3.   

    试试:
    SQL SERVER :
    select tt.i, case when 8 then 4 else tt.i end
    from
    (
      select isnull(t.i,0)
      from t
      order by t.i
    ) tt
    order by tt.i 
      

  4.   

    你这个题如果没写错的话就是取行号了,取行号需要用子查询,要不需要临时表,一条SQL 语句搞不定,除非DBMS本身有系统函数。
      

  5.   

    select (case when isnull(i,0)>4 then 4 else isnull(i,0) end) as i
    from Tb
    order by i