mysql - 如何仅更新日期数据类型的月份部分

标签 mysql sql-update

我试过这个:

update columnName set field1 = mdy(4,day(field1),year(field1))

但没有成功 u_U

我有这样的列:Day/01/2013 我只需将月份更改为 06

最佳答案

你能尝试一下吗:

update mytable set mydate=date_add(mydate, interval (xxx-month(mydate)) month);

其中 xxx 是您要将日期设置为的月份。

注意,来自 mysql 文档:

If you add MONTH, YEAR_MONTH, or YEAR and the resulting date has a day that is larger than the maximum day for the new month, the day is adjusted to the maximum days in the new month

关于mysql - 如何仅更新日期数据类型的月份部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17282857/

相关文章:

mysql - mssql转mysql出错

mysql - 多行数据读取器

sql - 如何使用 ms sql 进行更新和排序

有异常的 MySQL UPDATE 查询

php - 帮我为 iou Web 应用程序设计数据库架构

php - 从列表中选择行

php - 在 php 中上传图片 base64 时出现 2174 错误

mysql - Laravel Eloquent 或 DB 中的批量更新

MySQL - 如何更新小数列以允许更多位数?

postgresql - 在 PostgreSQL 9.2 中更新数据库行而不锁定表