我正在尝试从当天没有事件的场地表中检索行。
这是我检索事件的方式:
SELECT
events.*,
venues.*,
party_types.PARTYTYPE
FROM events
INNER JOIN venues
ON events.VENUE_LOCATION = venues.ID
WHERE start_datetime >= '$DATE_START_SELECTED'
AND end_datetime < '$DATE_END_SELECTED'
GROUP BY events.ID
$ DATE_START_SELECTED 和 $ DATE_END_SELECTED 是PHP变量,基本上说在Date1和Date2之间执行所有事件。
这就是我目前检索场地的方式:
SELECT
venues.*
FROM venues
GROUP BY venues.VENUE_NAME
如何检索所有场所 当天没有举办任何活动(取决于PHP变量)?
谢谢大家! :)
答案 0 :(得分:2)
SELECT
venues.*
FROM venues
LEFT JOIN events ON events.VENUE_LOCATION = venues.ID AND start_datetime >= '$DATE_START_SELECTED' AND end_datetime < '$DATE_END_SELECTED'
where events.VENUE_LOCATION IS NULL
GROUP BY venues.VENUE_NAME
答案 1 :(得分:1)
SELECT
venues.*,
FROM venues
LEFT JOIN events
ON events.VENUE_LOCATION = venues.ID
WHERE start_datetime >= '$DATE_START_SELECTED'
AND end_datetime < '$DATE_END_SELECTED'
AND events.VENUE_LOCATION IS NULL
答案 2 :(得分:1)
SELECT
venues.*
FROM venues
WHERE ID NOT IN (SELECT
VENUE_LOCATION
FROM events
WHERE start_datetime >= '$DATE_END_SELECTED'
OR end_datetime < '$DATE_START_SELECTED')
GROUP BY venues.VENUE_NAME