1
hellojinjie 2014-07-16 15:42:05 +08:00
select start_time from table where start_time < unix_timestamp() order by start_time desc
union select start_time from table where start_time >= unix_timestamp() order by start_time asc |
2
caofugui 2014-07-16 15:44:43 +08:00
首先这个用SQL去操作很蛋疼,程序上用两条SQL语句不就搞定?
其次设计上本身就不合理,过去时间跟未来时间怎么能混在一起呢? |
3
lu18887 2014-07-16 16:57:16 +08:00
@hellojinjie union正解
|
4
imxz OP @hellojinjie 谢谢你
|
5
imxz OP @hellojinjie 测试了一下,然后发现 order by子句必须写在最后一个结果集里,并且其排序规则将改变操作后的排序结果。 所以问题还是没有解决。。。
|
6
imxz OP 这样子就行了:
select * from (select * from `table` where `start_time` >= unix_timestamp() order by `start_time` asc)tmpa union select * from (select * from `table` where `start_time` < unix_timestamp() order by `start_time` desc)tmpb |