订单列表
订单列表中有没有设置服务时间的,有已经设置过服务时间的,现在需要查询订单,按订单的服务时间升序排列,但是要把没有设置服务时间(默认为1970年)放到最后面,用一个sql语句怎么解决呢?
ringa_lee2017-04-17 17:41:47
MySQL:
select * from t order by IF(ISNULL(order_col),1,0), order_col asc;
Oracle
select * from t order by order_col asc nulls last;
高洛峰2017-04-17 17:41:47
Use Union to merge query results.
(select * from a where service_time = !null order by service_time asc)
union
(select * from a where service_time = null);
Where post-condition can be modified accordingly according to your specific service_time default value.