select * from 表 where 字段A like '1%' and 字段B<>1
select * from 表 where 字段A like 'X%'
select * from 表 where 字段A like 'M%' or 字段B=1
select * from 表 where 字段A like 'X%'
select * from 表 where 字段A like 'M%' or 字段B=1
union
select 2 as 次序,* from 表 where 字段A like 'X%'
union
select 3 as 次序,* from 表 where 字段A like 'M%' or 字段B=1
union all
select * from 表 where 字段A like 'X%'
union all
select * from 表 where 字段A like 'M%' or 字段B=1
1、2、3中分别都要以字段C升序排列。
我试过用order by,但报错,是不是用了union就不能用order by了。
如何解决排序的问题啊?
union all
select * from #temp where 字段A like 'X%'
union all
select * from #temp where 字段A like 'M%' or 字段B=1
select * from (select * from 表1 order by 字段C)A where 字段A like '1%' and 字段B<>1
union all
select * from (select * from 表2 order by 字段C)A where 字段A like 'X%'
union all
select * from (select * from 表3 order by 字段C)A where 字段A like 'M%' or 字段B=1
select * from 表 where 字段A like '1%' and 字段B<>1
union all
select * from 表 where 字段A like 'X%'
union all
select * from 表 where 字段A like 'M%' or 字段B=1 )order by ...
select * from 表 where 字段A like '1%' and 字段B<>1
union all
select * from 表 where 字段A like 'X%'
union all
select * from 表 where 字段A like 'M%' or 字段B=1 ) xorder by x.字段A, x.字段B