求解运行的UPDATE建筑物SET building_name =“ Main Street Building” WHERE building_id = 2; 从那里,任务3查询将返回正确的结果。
任务一:
查询:
SELECT first_name, last_name, building_name, room.room_id, meeting_start,meeting_end
FROM meeting, person, person_meeting,room, building
WHERE room.room_id=meeting.room_id
AND meeting.meeting_id=person_meeting.meeting_id
AND person.person_id=person_meeting.person_id
AND room.building_id=building.building_id
AND person.first_name='Tom'
AND person.last_name='Hanks';
任务二:
查询:
SELECT first_name, last_name, building_name, room.room_id, meeting_start,meeting_end
FROM meeting, person, person_meeting,room, building
WHERE room.room_id=meeting.room_id
AND meeting.meeting_id=person_meeting.meeting_id
AND person.person_id=person_meeting.person_id
AND room.building_id=building.building_id
AND meeting.meeting_id=2;
任务三:
查询:
SELECT first_name, last_name, building_name, room.room_id,meeting.meeting_id, meeting_start, meeting_end
FROM meeting, person, person_meeting,room, building
WHERE room.room_id=meeting.room_id
AND meeting.meeting_id=person_meeting.meeting_id
AND person.person_id=person_meeting.person_id
AND room.building_id=building.building_id
AND building_name='Main Street Building';
任务四:
查询:
SELECT count(person_id) 'Count of meeting attendees', meeting.meeting_id,meeting_start,meeting_end
FROM meeting, person_meeting
WHERE meeting.meeting_id=person_meeting.meeting_id
GROUP BY meeting.meeting_id;
任务五:
查询:
SELECT first_name, last_name, meeting.meeting_id, meeting_start, meeting_end
FROM meeting INNER JOIN person_meeting ON meeting.meeting_id=person_meeting.meeting_id
INNER JOIN person ON person.person_id=person_meeting.person_id
AND meeting_start<'2016-12-25 12.00.00';
任务1,2,4,5和5都能完美运行。如果所有人都需要任务提示,请告诉我。
答案 0 :(得分:0)
注意:我尚未对此进行测试。
我根据我们最近的互动更改了查询。
这是您的原始照片
SELECT first_name, last_name, building_name, room.room_id,meeting.meeting_id, meeting_start, meeting_end
FROM meeting, person, person_meeting,room, building
WHERE room.room_id=meeting.room_id
AND meeting.meeting_id=person_meeting.meeting_id
AND person.person_id=person_meeting.person_id
AND room.building_id=building.building_id
AND building_name='Main Street Building';
这是我尝试构建的方式
根据文档的第2页和第3页,您提供了https://snhu.brightspace.com/d2l/lor/viewer/viewFile.d2lfile/76437/9523,2/,我将执行以下操作:
首先,我将获得有关建筑物的信息。
SELECT building_id
FROM building
WHERE building_name like '%Main Street Building%';
注意:我假设建筑物名称正确。但是,以防万一,我在名称前后使用通配符%
接下来,我将获得有关房间的信息:
SELECT b.building_name, r.room_id
FROM room r
LEFT JOIN building b
ON r.building_id = b.building_id
WHERE b.building_name like '%Main Street Building%';
在此之后,我将获得有关会议的信息:
SELECT b.building_name, r.room_id, m.meeting_id, m.meeting_start, m.meeting_end
FROM room r
LEFT JOIN building b
ON r.building_id = b.building_id
LEFT JOIN meeting m
ON r.room_id = m.room_id
WHERE b.building_name like '%Main Street Building%';
最后,我将获取将参加该会议的人员的ID信息并显示其姓名:
SELECT b.building_name, r.room_id, m.meeting_id, m.meeting_start, m.meeting_end, p.first_name, p.last_name
FROM room r
LEFT JOIN building b
ON r.building_id = b.building_id
LEFT JOIN meeting m
ON r.room_id = m.room_id
LEFT JOIN persom_meeting pm
ON m.meeting_id = pm.meeting_id
LEFT JOIN person p
ON pm.person_id = p.person_id
WHERE b.building_name like '%Main Street Building%';
如果这些查询不起作用,我建议您确保表之间存在关系。
这意味着表之间应该有building_id匹配,room_id匹配,meeting_id匹配和person_id匹配。另外,由于建筑物名称区分大小写,因此我会检查建筑物名称的拼写是否正确。
我使用LEFT JOIN的原因是,我可以显示先前表(所有行)的所有信息以及ID与外键ID匹配的记录。如此处所述:http://www.acarlstein.com/?p=4168
此外,在http://www.acarlstein.com/?p=4194中,我将展示两个左(外)连接如何工作。
但是,在您的情况下,它更像是一条正在构建的链,因此它与图不匹配,但是您也许可以理解我的意思。