目前我有一个产品表,一个用于价格,一个用于浇头,我使用以下代码构建我的JSON文件
SELECT `products`.`PrID` as `id`, `name`, group_concat(product_prices.size)as sizes, group_concat(product_prices.price)as prices, group_concat(product_toppings.IID)as IIDs
FROM `products`
JOIN `product_prices` ON `product_prices`.`PrID` = `products`.`PrID`
JOIN `product_toppings` ON `product_toppings`.`PrID` = `products`.`PrID`
WHERE `products`.`PrID` = '2'
AND `products`.`status` = 'active'
GROUP BY `products`.`PrID`
我目前的结果:
{"id":"2","name":"Hawaiian","sizes":"medium,medium,medium,medium,large,large,large,large,supersize,supersize,supersize,supersize","prices":"11.99,11.99,11.99,11.99,14.99,14.99,14.99,14.99,16.99,16.99,16.99,16.99","IIDs":"7,18,22,28,7,18,22,28,7,18,22,28"}
我知道我的问题在于分组,但我无法弄清楚如何将其分组,以便我得到类似的内容:
{"id":"2","name":"name","sizes":"medium,large,large,supersize","prices":"11.99,14.99,16.99","IIDs":"7,18,22,28"}