一个比较怪异的排序问题,要求排序字段(Name)将张三排在第一位,其它人按名字排序。
比如:
张三
李四
王五
赵六即先把张三放在第一位,其它人再来排序规则排序。请问这样的语句怎么写啊?

解决方案 »

  1.   

    select * from tb
    order by chareindex(name,'张三 ,李四,王五 ,赵六') 
      

  2.   


    order by  case when name='張三' then 0 else 1 end 
      

  3.   

    select * from tb order by case Name when '张三' then 1 else 2 end , name
      

  4.   

    select * from tb 
    ORDER BY 
    CASE WHEN name='张三' THEN 0 ELSE 1 END
    ,NAME
      

  5.   

    order by case when 了
      

  6.   

    select * from tb 
    ORDER BY 
    CASE WHEN name='张三' THEN 'A' ELSE name END
      

  7.   


    order by charindex(Name,'张三')
      

  8.   

    SQL版搶分是非常難的,大牛太多了。他們時刻都盯著版面,一旦有問題,在一分鐘之內就已經有數條回復了,象我們此等菜鳥只能跟在後面看了
      

  9.   

    if object_id('tb') is not null
    drop table tb
    go
    create table tb( num nvarchar(50))
    insert into tb
     
    select '张三'  union all
     select '李四'  union all
    select '王五'  union all
    select '赵六'select * from tb order by (case when num='张三' then 0 else 1 end)
     
      

  10.   


    --sinpoal
    if object_id('tb') is not null 
    drop table tb 
    go create table tb( name char(6)) 
    insert  tb select '张三'  union all 
    select '李四'  union all 
    select '王五'  union all 
    select '赵六' --------statement-------
    select * from tb order by (case when name='张三' then 0 else 1 end) 
      

  11.   

    select * from tb order by (case when name='张三' then 0 else 1 end) 
      

  12.   

    select name from table_1
    order by  case when name='張三' then 0 else 1 end