gpt4 book ai didi

mysql - 将这个多对多语句添加到我的语句中

转载 作者:行者123 更新时间:2023-11-29 14:32:32 25 4
gpt4 key购买 nike

我正在尝试创建一个多对多语句,但遇到问题。我正在尝试将多种音乐风格附加到一个事件,将它们放在一行中,并用逗号分隔它们。

这是我现在拥有的代码:

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

并收到此错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '== b.music_type_id AND b.event_id == events.ID' at line 14

说实话,我什至不知道应该如何回应它并将其分成逗号,你能帮我吗?多谢! :)

PS。我对这种关系的外观添加了一些视觉解释。 enter image description here

最佳答案

您的等于比较不正确:

AND a.id == b.music_type_id

应该是:

AND a.id = b.music_type_id 

关于mysql - 将这个多对多语句添加到我的语句中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9728718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com