0
我有這樣的查詢:實現嵌套GROUP_CONCAT
select p.id,
p.price,
concat('[',group_concat(concat('{',concat_ws(',', concat('color:', pc.color),concat('sizeName:',cs.size_name)),'}')),']') as variety
from tbl_products as p
inner join tbl_product_colors as pc on p.id = pc.product_id
left join tbl_color_sizes as cs on pc.id = cs.product_color_id
group by p.id;
查詢上述輸出:
Id | price | variety
1 | 1000 | [ {color:FFFFFF, sizeName:XL} , {color:FFFFFF, sizeName:X} ]
但我的期望的輸出是:
Id | price | variety
1 | 1000 | [ {color:FFFFFF, sizes: [ {sizeName: XL} , {sizeName: L} ] } ]
問題:如何在此上下文中使用group_concat或其他函數(除了JSON函數)來實現所需的輸出?
如果產品1有多種顏色,那麼期望的輸出是什麼? – Uueerdo
[{color:FFFFFF,sizes:[{sizeName:XL},{sizeName:L}]},{color:F2F2F2,sizes:[{sizeName:XL}]}] – Sajad
這將是一個'字段值? – Uueerdo