gpt4 book ai didi

mysql - 链接连接回目标表

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

我有四张 table

Survey          Question        Responses       Participants
============= ============== ============== =============
id_S id_Q id_R id_P
id_S id_Q id_S
id_P
id_S
Answer

我正在尝试弄清楚如何检索给出“D”作为问题 #3 答案的参与者的所有响应。

这是我的第一次尝试,但不出所料,它不起作用。

SELECT * 
FROM responses r
LEFT JOIN participants p
ON r.id_P = p.id_P
LEFT JOIN responses r2
ON p.id_R = r.id_P
WHERE r.id_S = 1 AND r2.Answer = "D" AND r2.id_Q = 1

By 不起作用,它返回太多记录。 SQL Select * FROM responses WHERE id_S =1 将返回 1,891 条记录,但上述热点问题返回 15,128 条记录。

很明显,我什至没有正确的概念来了解如何让它发挥作用,这不是一个简单的语法调整所需要的。

最佳答案

SELECT  ra.*
FROM responses rd
JOIN responses ra
ON (ra.id_s, ra.id_p) = (rd.id_s, rd.id_p)
WHERE (rd.id_q, rd.answer) = (3, 'D')

关于mysql - 链接连接回目标表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24323094/

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