开发者

MySQL using IF statements

开发者 https://www.devze.com 2023-03-10 19:00 出处:网络
I have a table with subscription values and want to calculate the time when the subscriptio开发者_如何学Pythonn expires.

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消