I'm trying to make a change this part of the sql
(To_days( now( )) - TO_DAYS( o.date_payed)) days1,
(To_days( no开发者_如何学JAVAw( )) - TO_DAYS( o.date_purchased)) days2,
This works fine, but I'm trying to make two changes, the first one is that I would like to this be just days1
and if the result of To_days( now( )) - TO_DAYS( o.date_payed)
is empty use the second one.
The second change would be to instead of using To_days
some way to use only weekdays, any ideas are welcome.
For the first question you can use IF function, ie
SELECT IF((o.date_payed IS NOT NULL)&&(To_days(now()) != TO_DAYS(o.date_payed))
,To_days(now()) - TO_DAYS(o.date_payed)
,To_days(now()) - TO_DAYS(o.date_purchased)
) AS days1 ...
For the second part you can use the date_format function, ie DATE_FORMAT(o.date_payed, '%w')
.
精彩评论