gpt4 book ai didi

MySql ADDDATE() 查询 : Adding two dates with 30 0r 60 days of period

转载 作者:行者123 更新时间:2023-11-29 08:26:12 30 4
gpt4 key购买 nike

我有一个名为“产品”的下表

product_id (BIGINT) | product_name (VARCHAR) | expiration_date (DATE) | entered_date (DATETIME) |
1234 | ABC | NULL | 2013-07-24 13:17:32 |
6789 | ABC | NULL | 2013-07-19 12:04:12 |
1234 | ABC | NULL | 2013-07-05 13:34:16 |
2343 | ABC | NULL | 2013-06-04 17:16:51 |

我想根据eneterd_date 列更新expiration_date 条目。如果entered_date + 30天> NOW(),则设置expiration_date =提前30天,否则expiration_date =提前60天

product_id (BIGINT) | product_name (VARCHAR) | expiration_date (DATE)  | entered_date (DATETIME) |
1234 | ABC | 2013-08-24 | 2013-07-24 13:17:32 |
6789 | ABC | 2013-08-19 | 2013-07-19 12:04:12 |
1234 | ABC | 2013-08-05 | 2013-06-05 13:34:16 |
2343 | ABC | 2013-08-24 | 2013-06-04 17:16:51 |

我正在尝试使用 MySql 中的 ADDDATE() 和其他日期函数,但到目前为止还没有任何好运气。

请告诉我您可以帮助我获得以下结果。

enter code here

最佳答案

试试这个(未经测试!)

 update product set expiration_date = (
select if(dateadd(entered_date, interval 30 day) > now(),
dateadd(entered_date,interval 30 day),
dateadd(entered_date,interval 60 day)))

关于MySql ADDDATE() 查询 : Adding two dates with 30 0r 60 days of period,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17844107/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com