SELECT FROM TABLE 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
结果来自TABLE1:
区域---主体
SB --- H1
BS --- H2
PT --- H2
TABLE2:
主机名---地区---状态
H1 --- SB --- 1
H2 --- PT --- 0
H2 --- BS --- 1个
如何在状态字段的表中UPDATE TABLE2
并将其设置为2,其中第一个选择(RESULT FROM TABLE1)的hostname = host
和第一个选择的region = region
(结果)从TABLE1)?
答案 0 :(得分:0)
这么容易。就像下面这样做:
UPDATE table2
INNER JOIN (your inner select) AS table1
ON (table2.hostname = table1.host AND table2.region = table1.region)
SET table2.status=2