上面是我的查询...但是observer_ID和staff_ID的相应名称在另一个名为staff的表中。所以我需要加入(o.observer_ID = s.staff_ID)AND(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'
答案 0 :(得分:1)
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'
答案 1 :(得分:0)
也许是一个自我内心的联系:
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
JOIN mbm2_db.Staff As s ON o.staff_ID = s.staff_ID
JOIN mbm2_db.Staff As b ON b.observer_ID = s.staff_ID
WHERE o.date = '2011-08-09' and o.Module_code = 'IS5103';
答案 2 :(得分:0)
SELECT DISTINCT o.Room, o.Date,o.Module_code,o.observer_ID,o.staff_ID,o.form_id
FROM mbm2_db.observation_details o, mbm2_db.Staff s
WHERE o.date = '2011-08-09'
AND o.Module_code = 'IS5103'
AND o.staff_ID=s.staff_ID
AND o.observer_ID=s.staff_ID
答案 3 :(得分:0)
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 LEFT JOIN mbm2_db.Staff AS observer ON o.observer_ID = oberver.staff_ID)
LEFT JOIN mbm2_db.Staff AS observed ON o.staff_ID = observed.staff_ID
WHERE o.date = '2011-08-09' and o.Module_code = 'IS5103'
告诉我它是否有效(并手动检查一些值)。