gpt4 book ai didi

mysql - 如何在 MariaDB 中选定行的帮助下更新列值?

转载 作者:行者123 更新时间:2023-11-29 01:28:34 25 4
gpt4 key购买 nike

我是 MariaDB 的新手。

我有一张 table 。每行都有自己的有效性。

CREATE TABLE `tariff_table` (
`transportation_id` int(11) NOT NULL AUTO_INCREMENT,
`transporter` varchar(300) NOT NULL,
`valid_upto` date NOT NULL,
`expired_status` int(11) NOT NULL DEFAULT '0',
`status` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`transportation_id`)
)

表格结果:

tariff_id || transporter || valid_upto || expired_status || status   
------------------------------------------------------------------
1 || Raj || 2014-12-08 || 0 || 0
2 || Ram || 2015-01-10 || 0 || 0
3 || Mani || 2014-03-06 || 0 || 0
4 || Mano || 2015-04-15 || 0 || 0

我的要求是,如何使用选择查询更新过期状态。

select tariff_id from tariff_table where valid_upto <= DATE(now());

选择查询返回 2 行。

tariff_id
---------
1
3

id 的帮助下,我需要更新如下。

我需要以下结果。

tariff_id || transporter || valid_upto || expired_status || status   
------------------------------------------------------------------
1 || Raj || 2014-12-08 || 1 || 0
3 || Mani || 2014-03-06 || 1 || 0

帮助我。

最佳答案

您可以使用 UPDATE 语句,如下所示:

UPDATE `tariff_table`
SET `expired_status` = 1
WHERE valid_upto <= DATE(now());

关于mysql - 如何在 MariaDB 中选定行的帮助下更新列值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27372769/

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