例如字段title和detail里有的放最前面
接着是只有在title有的
最后是只有detail里有的可以吗?

解决方案 »

  1.   

    order by case when title<>'' and detail<>0 then 0 
    when title<>'' then 1 end 
    -----------
    思路
      

  2.   


    select * from tablename
    order by case when title is not null and details is not null then 0
    when title is not null and details is null then 1
    else 2 end
      

  3.   


    create table tablename(title varchar(10),details varchar(10))insert into tablename
    select 'abc','ok'
    union
    select null,'efg'
    union
    select 'dfjkd',nullselect * from tablename
    order by case when title is not null and details is not null then 0
    when title is not null and details is null then 1
    else 2 end
      

  4.   

    例如字段title和detail里有的放最前面 
    接着是只有在title有的 
    最后是只有detail里有的 可以吗?select * from tb where charindex('关键字' , title) > 0 and charindex('关键字' , detail) > 0
    union 
    select * from tb where charindex('关键字' , title) > 0 and charindex('关键字' , detail) = 0
    union 
    select * from tb where charindex('关键字' , title) = 0 and charindex('关键字' , detail) > 0