怎样让表中固定的一列在最后,然后其他的按名称排序啊?project table:
ID     Name  
1      dev
2      test
3      other
4      good
5      bad我想让other固定在最后,其他的按照Name排序?除了order by case Name when 'Other' then 'zzzzzzzz' else Name end asc
之外, 有没有什么更好的办法呢?求各位赐教了。。

解决方案 »

  1.   


    这个方法能解决,但是万一出现了Name的值是‘zzzzzzzzzzzzzzzzzzzzzzz’的,这个就不行了
    虽然理论上不会出现,哈哈。我就是想知道有没有个好的方法能在排序时把某列固定在最后一行呢?
      

  2.   

    order by case Name when 'Other' then (select max(Name)+'1' from table) else Name end asc 可以了,给分
      

  3.   

    还有一个比较繁琐,哈哈。其实你那个就很简单啦。
    select * from (select top 100 * from table where name <>'Other' order by name) t1
    UNION 
    select * from (select * from table where name ='Other' ) t2
    这里要说下, order by 必需出现在union 后。。
    所以这里要用子查询。。还要加top才行。。