MySQL:ORDER BY,最后一个空日期为'0000-00-00',其余为ASC [英] MySQL: ORDER BY with empty date '0000-00-00' as last but the rest ASC

查看:67
本文介绍了MySQL:ORDER BY,最后一个空日期为'0000-00-00',其余为ASC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的数据库中,它们不是'0000-00-00'(而不是空日期)(我知道,它很烂).我该如何排序,以使不是'0000-00-00'的日期是第一个,然后是ASC,然后是'0000-00-00'的空日期呢?

In our database, instead of making empty dates NULL, they are '0000-00-00' (I know, it sucks). How can I order these so that dates that are not '0000-00-00' are first and ordered ASC, and then the empty dates of '0000-00-00' come after?

谢谢!

推荐答案

...
ORDER BY CASE WHEN YourDateColumn = '0000-00-00' THEN 2 ELSE 1 END,
         YourDateColumn

这篇关于MySQL:ORDER BY,最后一个空日期为'0000-00-00',其余为ASC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆