MySQL订单商品(最新的2个日期) [英] Mysql order items by the newest of 2 dates
本文介绍了MySQL订单商品(最新的2个日期)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有2个日期的表-ADDDATE和UPDATEDATE.
添加项目后,ADDDATE是当前日期,而UPDATEDATE是0000-00-00.
I have a table with 2 dates - the ADDDATE and UPDATEDATE.
When an item is added, the ADDDATE is the current date and the UPDATEDATE is 0000-00-00.
我需要ORDER BY
SQL命令并获得那些2的最佳日期.
例如,如果ADD = 12/1/2010和UPDATE = 30/6/2010,
UPDATE DATE最好(最新).
I need to ORDER BY
the SQL command and get the best date of those 2.
For example if ADD=12/1/2010 and UPDATE=30/6/2010,
the UPDATE DATE is best (newest).
有什么建议吗?
推荐答案
使用 GREATEST 查找最新日期:
ORDER BY GREATEST(UPDATEDATE, ADDDATE)
这篇关于MySQL订单商品(最新的2个日期)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文