假设有一个SQL这样的:
select * from table_name where caption like '%关键字%' or memo like '%关键字%' 
我想排序里,让满足caption 里有“关键字”的内容的先显示出来,如果caption里没有,在显示memo里有“关键字”的内容的
大家碰过这样的排序吗?

解决方案 »

  1.   


    select   *   from   table_name   where   caption   like   '%关键字%'  order by caption union all  select   *   from   table_name   where  memo   like   '%关键字%' order by memo;
      

  2.   

    --可以这样试试.select * from table_name 
    where caption like '%tt%' or memo like '%ad%' 
    order by case when caption like '%tt%' then 0 else 1 end;