gpt4 book ai didi

mysql - 加入MYSQL查询问题

转载 作者:行者123 更新时间:2023-11-29 00:53:58 25 4
gpt4 key购买 nike

上面是我的查询...但是 observer_ID 和 staff_ID 的对应名称在另一个名为 staff 的表中。所以我需要如何加入 (o.observer_ID=s.staff_ID) 和 (o.staff_ID=s.staff_ID) 以获得观察者和被观察者的两个名字 (o.staff_ID)。请帮助我。谢谢

SELECT DISTINCT o.Room, o.Date,o.Module_code,o.observer_ID,o.staff_ID,o.form_id
FROM mbm2_db.observation_details as o,mbm2_db.Staff as s
WHERE o.date = '2011-08-09' and o.Module_code = 'IS5103'

最佳答案

SELECT DISTINCT 
o.Room, o.Date,o.Module_code,o.observer_ID,o.staff_ID,o.form_id,
s1.name, s2.name
FROM
mbm2_db.observation_details AS o
LEFT JOIN mbm2_db.Staff AS s1 ON o.observer_ID = s1.staff_ID
LEFT JOIN mbm2_db.Staff AS s2 ON o.staff_ID = s2.staff_ID
WHERE
o.date = '2011-08-09' AND o.Module_code = 'IS5103'

关于mysql - 加入MYSQL查询问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6999837/

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