gpt4 book ai didi

mysql - 在 MYSQL 表中包含另一个联接

转载 作者:行者123 更新时间:2023-11-29 17:54:08 25 4
gpt4 key购买 nike

我创建了以下查询,其中包含 2 个联接:

SELECT a.name, b.tid
FROM table1 a INNER JOIN
table2 b
ON a.id = b.id
INNER JOIN (
SELECT b2.id, b2.status, MAX(b2.created_time) as max_time
FROM oac.qualys_scan b2
GROUP BY b2.id , b2.qualys_type
) t on t.id = a.id
AND t.status=b.status
AND t.max_time = b.created_time
WHERE b.status = 'FAIL';

输出如下:

id      tid     name
17695 19512 abc.com
17781 19628 abc1.com
17805 19732 abc2.com
17806 19703 abc3.com
17807 19704 abc4.com

我有另一个表 table3,它具有以下值

id  tid     name                        details
842 19512 abc.com Details Description 1
843 19628 abc1.com Details Description 2

我想将上述查询与 tid 上的 table3 结合起来,以便获得以下输出

id      tid     name          details      
17695 19512 abc.com Details Description 1
17781 19628 abc1.com Details Description 1

最佳答案

那么它只是 table1 a 上的另一个内部联接:

 SELECT a.id, b.tid, a.name,  table3.details
FROM table1 a INNER JOIN
table2 b
ON a.id = b.id
INNER JOIN (
SELECT b2.id, b2.status, MAX(b2.created_time) as max_time
FROM oac.qualys_scan b2
GROUP BY b2.id , b2.qualys_type
) t on t.id = a.id
AND t.status=b.status
AND t.max_time = b.created_time
INNER JOIN table3 on b.tid = table3.tid
WHERE b.status = 'FAIL';

关于mysql - 在 MYSQL 表中包含另一个联接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49012534/

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