MySQL 使用 IF 语句

发布于 2024-11-13 01:06:13 字数 366 浏览 0 评论 0原文

我有一个包含订阅值的表,想要计算订阅到期的时间。

我使用以下语句:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月牙弯弯 2024-11-20 01:06:13

因为它不是选择的一部分

    SELECT contractType, paymentReceivedOn,
IF (contractType = 'abo3', ADDDATE(paymentReceivedOn, INTERVAL 3 MONTH), NULL)  
AS expiryDate FROM payments WHERE id=21

应该可能有效

(从间隔中删除了引号)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文