通过使用date()函数匹配日期来更新MySQL表列?
以下是将date与date()函数进行匹配并更新列的语法-
update yourTableName set yourColumnName=yourValue where date(yourColumnName)=curdate();
让我们首先创建一个表-
create table DemoTable1816(
Name varchar(20),
JoiningDate datetime
);
使用插入命令在表中插入一些记录-
insert into DemoTable1816 values('Chris','2019-11-29 12:34:50');insert into DemoTable1816 values('David','2019-11-30 11:00:00');
insert into DemoTable1816 values('Mike','2018-11-30 10:20:30');
使用select语句显示表中的所有记录-
select * from DemoTable1816;
这将产生以下输出-
+-------+---------------------+| Name | JoiningDate |
+-------+---------------------+
| Chris | 2019-11-29 12:34:50 |
| David | 2019-11-30 11:00:00 |
| Mike | 2018-11-30 10:20:30 |
+-------+---------------------+
3 rows in set (0.00 sec)
这是通过匹配日期来更新列的查询-
update DemoTable1816 set Name='Robert' where date(JoiningDate)=curdate();Rows matched: 1 Changed: 1 Warnings: 0
让我们再次检查表记录-
select * from DemoTable1816;
这将产生以下输出-
+--------+---------------------+| Name | JoiningDate |
+--------+---------------------+
| Chris | 2019-11-29 12:34:50 |
| Robert | 2019-11-30 11:00:00 |
| Mike | 2018-11-30 10:20:30 |
+--------+---------------------+
3 rows in set (0.00 sec)
以上是 通过使用date()函数匹配日期来更新MySQL表列? 的全部内容, 来源链接: utcz.com/z/327328.html