从表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的结果:


  区域---主机SB --- H1 BS --- H2 PT --- H2


表2:


  主机名---区域---状态H1 --- SB --- 1 H2 --- PT --- 0 H2 --- BS --- 1


如何在表中的状态字段中将UPDATE TABLE2设置为2,其中第一个选择的hostname = host(来自表1的结果)和第一选择的region = 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/

10-13 21:27