我正在学习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;
不要混合使用隐式和显式连接
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;
我改变了,但是却一无所有
CREATE OR REPLACE 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.concert_halls ch
INNER JOIN project.events ev ON ch.id_concert_hall = ev.id_concert_hall
INNER JOIN project.concerts co 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;