gpt4 book ai didi

mysql - 更新来自 SELECT 的数据

转载 作者:行者123 更新时间:2023-11-29 20:11:56 27 4
gpt4 key购买 nike

从表 1 中选择:

SELECT a.region,a.host 
FROM ftpup a
, ( SELECT info,type,timestamp, max(date) as time FROM ftpup GROUP BY type ) b
WHERE a.type = b.type AND a.date = b.time AND a.status <> '0' ORDER BY a.`date` DESC

表 1 的结果:

region --- host
SB --- H1
BS --- H2
PT --- H2

表2:

hostname --- region --- status
H1 --- SB --- 1
H2 --- PT --- 0
H2 --- BS --- 1

如何在状态字段的表中UPDATE TABLE2并将其设置为2,其中第一个选择的hostname = host(RESULT FROM TABLE1)和region = 第一个选择的区域(表 1 的结果)?

最佳答案

就这么简单。只需像下面这样做:

UPDATE table2
INNER JOIN (your inner select) AS table1
ON (table2.hostname = table1.host AND table2.region = table1.region)
SET table2.status=2

关于mysql - 更新来自 SELECT 的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40035763/

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