我在MySQL中运行一个select查询:
SELECT *
FROM table1
ORDER BY IF(duedate = '0000-00-00 00:00:00', datetime_added, duedate) ASC
它的排序ASC但是它将所有0000-00-00 00:00:00
的行放在顶部,但这些行应该在底部
如何按以下顺序订购查询:
duedate ASC
datetime_added ASC
sequence DESC
答案 0 :(得分:1)
试试这个:
SELECT *
from table1
ORDER BY IF(duedate = '0000-00-00 00:00:00', '9999-12-31', duedate),
datetime_added ASC,
sequence DESC
答案 1 :(得分:0)
您可以通过以下方式执行此操作:
SELECT * from table1
ORDER BY
duedate ASC,
duedate = '0000-00-00 00:00:00',
datetime_added ASC,
sequence DESC