我正在学习SQL,我需要进行查询以提供所有事件,但是我有特殊性。 FK id_festival可以为null,表事件中的nb_tickets_sold列也可以为null。
我尝试进行以下查询,但没有结果
CREATE VIEW project.showEvents AS
SELECT ev.id_event AS "ID",
ev.event_name AS "Name",
ev.price AS "Price",
fe.festival_name AS "Festival",
ev.event_date AS "Date",
ch.concert_hall_name AS "Hall"
FROM project.concerts co, project.concert_halls ch,
project.events ev LEFT OUTER JOIN project.festivals fe ON ev.id_festival = fe.id_festival
WHERE ev.id_event = co.id_event
AND ev.id_concert_hall = ch.id_concert_hall
ORDER BY ev.event_date;
答案 0 :(得分:1)
不要将隐含和显式加入
CREATE VIEW project.showEvents AS
SELECT ev.id_event AS "ID",
ev.event_name AS "Name",
ev.price AS "Price",
fe.festival_name AS "Festival",
ev.event_date AS "Date",
ch.concert_hall_name AS "Hall"
FROM project.concerts co
INNER JOIN project.concert_halls ch ON ev.id_concert_hall = ch.id_concert_hall
INNER project.events ev ON ev.id_event = co.id_event
LEFT OUTER JOIN project.festivals fe ON ev.id_festival = fe.id_festival
ORDER BY ev.event_date;