MySQL 使用 IF 语句
我有一个包含订阅值的表,想要计算订阅到期的时间。
我使用以下语句:
SELECT contractType, paymentReceivedOn FROM payments WHERE id=21
AND IF (contractType = 'abo3', ADDDATE(paymentReceivedOn, 'INTERVAL 3 MONTH') AS expiryDate, 0)
如果我省略 AS expiryDate 部分,我的上述语句将有效,但是,我似乎无法从 ADDDATE 的计算中获得结果。
如何调整我的查询,以便它根据 paymentReceivedOn + 3 个月给出 expiryDate?
I have a table with subscription values and want to calculate the time when the subscription 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为它不是选择的一部分
应该可能有效
(从间隔中删除了引号)
Because its not part of the selection
Should probably work
(removed quotes from round the interval)