检索当天没有活动的场地

时间:2012-04-02 13:45:36

标签: mysql

我正在尝试从当天没有事件场地表中检索行。

这是我检索事件的方式:

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变量)?

谢谢大家! :)

3 个答案:

答案 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