Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想编写一个返回单个日期值的查询,该值是两列中最新的。
因此,如果我有一个值 a、b、date1、date2 的表,我想要类似的东西:
SELECT a, b, (Greater of date1 and date2) as date FROM...
这可能吗?
您可以使用GREATEST功能。
SELECT a, b, GREATEST(date1,date2) as date FROM...
您可以使用IF 语句
SELECT a, b, IF(date1>date2, date1, date2) as date
只是我们的IF功能...
IF
SELECT a, b, IF (date1 > date2, date1, date2) AS 'date' FROM yourtable
...或将其与GREATEST:
GREATEST
SELECT a, b, GREATEST(date1, date2) AS 'date' FROM yourtable