0

我试图接受这个查询:

SELECT
    events.ID,
    events.EVENT_NAME,
    GROUP_CONCAT(music_styles.MUSIC_STYLE_NAME) AS MUSIC_STYLE_NAME
FROM events
INNER JOIN events_music_styles
    ON events.ID = events_music_styles.event_id
INNER JOIN music_styles
    ON events_music_styles.music_style_id = music_styles.id
GROUP BY events.ID

效果很好,我做了这个:

$id = (int) $_GET['id'];
$data2 = mysql_query("
SELECT 
    events.ID,
    events.EVENT_NAME,
    events.SHORT_EVENT_DESC,
    events.SMALL_POSTER_URL,
    events.start_datetime,
    events.VENUE_LOCATION
    GROUP_CONCAT(music_styles.MUSIC_STYLE_NAME) AS MUSIC_STYLE_NAME
FROM 
    venues
INNER JOIN events
    ON events.VENUE_LOCATION = venues.ID 
INNER JOIN events_music_styles
    ON events.ID = events_music_styles.event_id
INNER JOIN music_styles
    ON events_music_styles.music_style_id = music_styles.id
WHERE
    events.VENUE_LOCATION = venues.ID
AND
    WHERE start_datetime >= '$DATE_START_SELECTED'
AND 
    venues.id = ".$id."
GROUP BY events.start_datetime) or die(mysql_error());

这给了我两个错误:

首先是与集团 Concat:

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以了解在 'GROUP_CONCAT(music_styles.MUSIC_STYLE_NAME) AS MUSIC_STYLE_NAME FROM avenues IN' 附近使用的正确语法

我知道我主要从venues表格中检索数据,但是加入events表格时是否重要?

第二个是Group by我有:

解析错误:语法错误,意外的 T_ENCAPSED_AND_WHITESPACE,需要 T_STRING 或 T_VARIABLE 或 T_NUM_STRING

我以为我关闭了所有字符串,所以我不确定它为什么会这样做。

4

1 回答 1

4

前面少了一个逗号GROUP_CONCAT,仅此而已!

编辑:

第二个也是错字:最后一行缺少引号,

GROUP BY events.start_datetime) or die(mysql_error());

应该

GROUP BY events.start_datetime") or die(mysql_error());
于 2012-12-31T16:05:52.563 回答