Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在表格中有行日期时间格式2013-01-01 01:01:01我想要更新,日期行和所有年份从2013到2012
2013-01-01 01:01:01
2013
2012
我的SQL UPDATE票SET YEAR(t_date ) = 2012 WHERE YEAR(t_date) = 2013
SQL UPDATE
SET YEAR(
) = 2012 WHERE YEAR(
) = 2013
但是这样不行,有什么问题吗?
SELECT date_Add(t_date - INTERVAL 1 YEAR), t_date FROM your TableName where year(T_Date) =2013 Update yourTableName set t_date= date_Add(t_date-Interval 1) YEAR WHERE year(T_DATE) = 2013
您的方法不起作用,因为您的语法不正确。检查手册
确切链接
错误在于这YEAR(t_date)是函数的结果,您无法更新函数的结果。
YEAR(t_date)
你可以做
update tickets set t_date = date_add(t_date, interval -1 year) where year(t_date) = 2013