我花了好几个小时使用phpMyAdmin正确地进行此查询,当我已经将它传输到我的laravel项目时,它说有一个错误,我真的不明白错误是什么。
SELECT GROUP_CONCAT(DISTINCT CONCAT(
'SUM( CASE WHEN rate_sub_type = ''',rate_sub_type,''' THEN rate END ) AS rate_sub_type'
)
) INTO @sql
FROM rate_sub_types;
SET @query = CONCAT('SELECT rate_type, name, ', @sql, '
FROM rate_types a, rate_sub_types b, rates c
where a.id=b.rate_type_id and b.id=c.rate_sub_type_id and c.amenity_id is null GROUP BY rate_type, name
UNION
SELECT rate_type, d.name, ', @sql, '
FROM rate_types a, rate_sub_types b, rates c, amenities d
where a.id=b.rate_type_id and b.id=c.rate_sub_type_id and d.id=c.amenity_id
GROUP BY rate_type, d.name');
PREPARE stmt FROM @query;
EXECUTE stmt;
这些是错误......
有人能帮我吗?非常感谢你