我正在尝试对以下查询返回的结果进行 GROUP_CONCAT:
SELECT
CONCAT(p.product_name, " (", SUM(bp.quantity), ")") AS products
FROM product p
INNER JOIN booking_products bp ON p.product_id = bp.product_id
GROUP BY p.product_id
此查询返回以下内容:
------------
| products |
------------
Shampoo (3)
Advil (1)
Dry Shampoo (4)
Cepacol (5)
当我尝试运行下面的查询时,我收到一个错误:“#1111 - 组函数的使用无效”。这有什么问题?
SELECT
GROUP_CONCAT(
CONCAT(p.product_name, " (", SUM(bp.quantity), ")")
SEPARATOR ", "
) AS products
FROM product p
INNER JOIN booking_products bp ON p.product_id = bp.product_i
GROUP BY p.product_id
当然它应该返回:
Shampoo (3), Advil (1), Dry Shampoo (4), Cepacol (5)
谢谢你的帮助。