有一张定时任务生效表,对于没生效的任务,我们希望按照预计生效时间正序排序,已经生效的任务按照预计生效时间倒叙排序,同时没生效的任务都在已生效的任务上面 ,对于这样的同一个字段根据不同条件排序可以参照一下代码
SELECT
`status`,
IF
( `status` = 0, unix_timestamp( effective_time ),- unix_timestamp( effective_time ) ) sort,
effective_time
FROM
lottery_buff
WHERE
state = 1
ORDER BY
`status` ASC,
sort ASC