我正在尝试创建许多声明,但我遇到了问题。 我正在尝试将多个音乐风格附加到一个事件中,将它们放在一行中,然后用逗号分隔它们。
这是我现在的代码:
SELECT a.* FROM music_types AS a, events_music_types AS b WHERE a.id == b.music_type_id AND b.event_id == events.ID
我正试图将它附加到我现在拥有的东西上:
SELECT
events.EVENT_NAME, events.start_datetime, events.end_datetime, events.VENUE_LOCATION, events.PARTY_TYPE, events.IMAGE_URL, events.ENTRANCE_PRICE,
venues.VENUE_NAME, venues.BEER_PRICE, venues.WINE_PRICE, SPIRITS_PRICE,
party_types.PARTYTYPE
FROM events
INNER JOIN venues
ON events.VENUE_LOCATION = venues.ID
INNER JOIN party_types
ON events.PARTY_TYPE = party_types.ID
WHERE start_datetime >= '$DATE_START_SELECTED'
AND end_datetime < '$DATE_END_SELECTED'
我做到了这一点:
SELECT
events.EVENT_NAME, events.start_datetime, events.end_datetime, events.VENUE_LOCATION, events.PARTY_TYPE, events.IMAGE_URL, events.ENTRANCE_PRICE,
venues.VENUE_NAME, venues.BEER_PRICE, venues.WINE_PRICE, SPIRITS_PRICE,
party_types.PARTYTYPE,
a.*
FROM events
INNER JOIN venues
ON events.VENUE_LOCATION = venues.ID
INNER JOIN party_types
ON events.PARTY_TYPE = party_types.ID
INNER JOIN music_types AS a, events_music_types AS b
WHERE start_datetime >= '$DATE_START_SELECTED'
AND end_datetime < '$DATE_END_SELECTED'
AND a.id == b.music_type_id
AND b.event_id == events.ID
得到了这个错误:
您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 第14行'== b.music_type_id AND b.event_id == events.ID'附近
说实话,我甚至不确定如何回应并将其分成逗号,你能帮助我吗?非常感谢! :)
PS。我添加了一些关于这种关系的视觉解释。
答案 0 :(得分:1)
您的等同比较不正确:
AND a.id == b.music_type_id
应该是:
AND a.id = b.music_type_id