
1 hellojinjie 2014 年 7 月 16 日 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 年 7 月 16 日 首先这个用SQL去操作很蛋疼,程序上用两条SQL语句不就搞定? 其次设计上本身就不合理,过去时间跟未来时间怎么能混在一起呢? |
3 lu18887 2014 年 7 月 16 日 @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 |