select * from tablename where id not like '%%' union select * from tablename where id like '%%'
--先认为设置个排序号,再排序 select dataCol,serialno,... from (select 1 as serialno, dataCol,table.* from table where ... and not (特殊条件) union select 2 as serialno, dataCol,table.* from table where 特殊条件 ) xxx order by dataCol,serialno asc (如果有其他排序字段,加到这后边)
select * from tablename where id != 'aa' order by id
union select * from tablename where id = 'aa'
where id not like '%%'
union
select * from tablename
where id like '%%'
select dataCol,serialno,... from
(select 1 as serialno, dataCol,table.* from table where ... and not (特殊条件)
union
select 2 as serialno, dataCol,table.* from table where 特殊条件
) xxx
order by dataCol,serialno asc (如果有其他排序字段,加到这后边)
2 2013-6-24 2
3 2013-6-24 6
4 2013-6-24 364
5 2013-6-24 394
6 2013-6-24 4481
7 2013-6-25 1
8 2013-6-25 2
9 2013-6-25 6
10 2013-6-25 364
11 2013-6-25 394
12 2013-6-25 4481
13 2013-6-24 371
14 2013-6-25 371
用union连接后是如上结果的,但希望371这个特殊数据,分别排在6-24和6-25最后。
就这么个意思:
order by case when xh=371 then null else sj end nulls last,sj--
或者不需要nulls last,也可以故意把sj设置一个升序中的绝对大的值(如果是升序排序)