With if in a where statement I'm trying to get all rows where datetime is larger then NOW(), but if type = 'economy', i would like to constraint it to only show if datediff between datetime and NOW() is larger than 14 days.
Something like:
Select type,date(datetime) as date
from tbl1
where datetime > NOW()
IF(type = 'economy') && datediff(datetime,NOW()) > 14
order by datetime desc
I've tried with case when also, but can't figure it out...
You can just separate the criteria into 2 different comparisons:
select type,date(datetime) as date
from tbl1
where (datetime > NOW() AND type <> 'economy') OR
(datediff(datetime, NOW()) > 14 AND type = 'economy')
order by datetime desc
(Not checked for syntax errors, but the idea should be right...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With