MySQL using IF statements
I have a table with subscription values and want to calculate the time when the subscriptio开发者_如何学Pythonn expires.
I use the following statement:
SELECT contractType, paymentReceivedOn FROM payments WHERE id=21
AND IF (contractType = 'abo3', ADDDATE(paymentReceivedOn, 'INTERVAL 3 MONTH') AS expiryDate, 0)
My above statement works if I leave out the AS expiryDate part, however, then I cannot seem to get the result from the caculation of ADDDATE out.
How can I adjust my query so that it gives me the expiryDate based on paymentReceivedOn + 3 months?
Because its not part of the selection
SELECT contractType, paymentReceivedOn,
IF (contractType = 'abo3', ADDDATE(paymentReceivedOn, INTERVAL 3 MONTH), NULL)
AS expiryDate FROM payments WHERE id=21
Should probably work
(removed quotes from round the interval)
精彩评论