[英]MySQL select extra column if date is in future
I need to check whether my date
field is in the future using MySQL and if so, add an extra column. 我需要检查
date
字段是否将来使用MySQL,如果是,请添加额外的列。 It's important that I do not want to make this part of my where clause as I want to return rows where the date
field is not in the future. 重要的是,我不想将其成为where子句的一部分,因为我想返回
date
字段不在将来的行。
For example: 例如:
select
dateIsInFuture = 'true' if date > now()
I know the above is not valid syntax but I need to know how to write that in a valid SQL statement. 我知道上面的语法无效,但是我需要知道如何在有效的SQL语句中编写该语法。
Thanks 谢谢
select *, case when date_col > now()
then 'true'
else 'false'
end as dateIsInFututre
from your_table
您可以使用if ,但是使用以下语法:
SELECT IF(date > now(), 'true', 'false') as FutureFlag FROM YOUR_TABLE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.