比如要按照字段type字母升序排序,ORDER BY type就可以,但是其中有一个叫"OTHER"的希望永远放在最后,如何实现呢?

解决方案 »

  1.   

    declare @t table(a varchar(10))
    insert into @t select 'aa'
    insert into @t select 'vd'
    insert into @t select 'gr'
    insert into @t select 're'
    insert into @t select 'bb'
    insert into @t select 'other'select * from @t order by case a when 'other' then (select max(a)+'1' from @t) else a end--这样?
      

  2.   

    这样行不?
    select * into #temp from table_name where type<>'other' order by type
    select * from #temp
    union all
    select * from table_name where type='other'
      

  3.   

    Select * From @t Order By Case type When 'other' Then 1  Else 0 End,type不用再計算一次啊。
      

  4.   

    declare @t table(a varchar(10))
    insert into @t select 'aa'
    insert into @t select 'vd'
    insert into @t select 'gr'
    insert into @t select 're'
    insert into @t select 'other'
    insert into @t select 'bb'--放在最前面
    select * from @t order by case a when 'other' then  char(0) else a end
    --放在最后面
    select * from @t order by case a when 'other' then  char(255) else a end
      

  5.   

    确实写复杂了。按type再排一下就可以了
      

  6.   

    xeqtr1982还想着上次的排序题吧
      

  7.   

    then  char(0) 
    这个什么意思?
      

  8.   

    我也是受上次题的干扰才想到Char(0)的,失败!