考虑一个表DateDetails,其中有一列 effectiveDate。 我想编写一个更新查询:
if effectiveDate > "first day of the month" then
->set it to "first day of the month"
类似于:
update DateDetails
set effectiveDate = (start of the month)
where effectiveDate > (start of the month)
effectiveDate 的类型为 DATE。日、月、年也可以是任意:12-JAN-2013 或 24-DEC-2056
我该如何写这个?
最佳答案
update DateDetails
set effectiveDate = DATE_FORMAT(start_date ,'01-%b-%Y')
where effectiveDate > start_date;
将所有日期更改为生效日期当月的第一天
update DateDetails
set effectiveDate = DATE_FORMAT(effectiveDate ,'01-%b-%Y');
关于mysql - 更改 SQL 中的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17724959/