gpt4 book ai didi

mysql - DATE_ADD 函数在更新中不起作用

转载 作者:行者123 更新时间:2023-11-29 22:00:28 27 4
gpt4 key购买 nike

我正在尝试以下 SQL:

update Sales_details set due_date = DATE_ADD(last_sale_date, INTERVAL 35 DAY) where task = 230

并出现以下错误

syntax error: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INTERVAL35DAY) FROM Sales_details WHERE task = 230' at line 1

我尝试了以下 SQL,它工作正常:

select last_sale_date, DATE_ADD(last_sale_date, INTERVAL 35 DAY) from Sales_details where task = 230

为什么DATE_ADDUpdate语句中不起作用?

最佳答案

适用于 mysql!!你的语法错误-你在sqlserver中使用mysql的语法,

请检查 SQLSERVER 的 ADDDATE 语法

SQL Server DATEADD() Function
DATEADD(datepart,number,date)


MySQL DATE_ADD() Function
DATE_ADD(date,INTERVAL expr type)


mysql> select first_name,birth_date from students where first_name = 'Dale';
+------------+------------+
| first_name | birth_date |
+------------+------------+
| Dale | 1959-03-29 |
+------------+------------+
1 row in set (0.00 sec)

mysql> update students set birth_date = DATE_ADD(birth_date,interval 35 DAY) where first_name = 'Dale';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select first_name,birth_date from students where first_name = 'Dale'; +------------+------------+
| first_name | birth_date |
+------------+------------+
| Dale | 1959-05-03 |
+------------+------------+
1 row in set (0.00 sec)

mysql>

关于mysql - DATE_ADD 函数在更新中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32708019/

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