如我想让表1中的NAME字段为张三的始终在前面显示

解决方案 »

  1.   

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

  2.   

    select  *
    from 表1
    order by case when name='张三' then 0 else 1 end,其他排序字段
      

  3.   

    order by charindex('张三',NAME) desc
      

  4.   

    这样?
    create table test(name nvarchar(20))
    insert test select N'赵六'
    union all select N'李四'
    union all select N'张三'
    union all select N'王五'select name from test
    order by case when name=N'张三' then 0
    else 1 enddrop table testname                 
    -------------------- 
    张三
    王五
    赵六
    李四
      

  5.   

    select * from (select a.*,type = '1' from a where name = '張三' union all
    select a.*,type = '0' from a where name <> '張三') order by desc
      

  6.   

    反了
    order by charindex(NAME,'张三') desc
      

  7.   

    --借用一下数据
    create table test(name nvarchar(20))
    insert test select N'赵六'
    union all select N'李四'
    union all select N'张三'
    union all select N'王五'select name from test
    order by charindex(name,'张三') descdrop table test
    /*
    name                 
    -------------------- 
    张三
    王五
    赵六
    李四(4 row(s) affected)
    */
      

  8.   

    order by case when name='张三' then 0 else 1 end asc 最合题意charindex(name,'张三') desc 有误差
    name 是'张' 和 '张三' 那结果是一样的,有可能导致张排在前面
    如果name是'三',就肯定会排在张三前面