如select * from a1 where a1.title1 like '第一 ' or a1.title2 like '第二 ' order by id desc 我想将符合第一个条件(a1.title1 like '第一 ' )的数据全都放在第二个条件的数据前面 --------------------------------------------------select * from a1 where a1.title1 like '第一' union all select * from a1 where a1.title2 like '第二'
select * from ( select * ,row = 1 from a1 where a1.title1 like '第一' union all select * ,row = 2 from a1 where a1.title2 like '第二' ) t order by row , id desc
select * from a1 where a1.title1 like '第一 ' or a1.title2 like '第二 ' order by title1 desc,id desc
select * from a1 order by case when charindex('第一',a1.title1)>0 then 0 else 1 end
--------------------------------------------------select * from a1 where a1.title1 like '第一'
union all
select * from a1 where a1.title2 like '第二'
(
select * ,row = 1 from a1 where a1.title1 like '第一'
union all
select * ,row = 2 from a1 where a1.title2 like '第二'
) t
order by row , id desc
order by title1 desc,id desc