[英]SQL order by 2 date fields
i am running a select query in MySQL: 我在MySQL中运行选择查询:
SELECT *
FROM table1
ORDER BY IF(duedate = '0000-00-00 00:00:00', datetime_added, duedate) ASC
its ordering ASC but it puts all rows that have 0000-00-00 00:00:00
at the top but these should be at the bottom 它的排序ASC,但将所有顶部具有
0000-00-00 00:00:00
行放在顶部,但这些行应该在底部
How can I order my query in the following order: 如何按以下顺序排序查询:
duedate ASC
datetime_added ASC
sequence DESC
Try this: 尝试这个:
SELECT *
from table1
ORDER BY IF(duedate = '0000-00-00 00:00:00', '9999-12-31', duedate),
datetime_added ASC,
sequence DESC
you can do this by: 您可以通过以下方式做到这一点:
SELECT * from table1
ORDER BY
duedate ASC,
duedate = '0000-00-00 00:00:00',
datetime_added ASC,
sequence DESC
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.