有没有办法让您在SqlFiddle中看到的架构显示为:
SKU | size S | size M | size L | init_qty | qty
? 我试图使用GROUP_CONCAT,这不是我想要的。
这是我的查询
select sku, name, group_concat(taglie separator ';') as `Magazzino`
from
(
select p.sku, p.name, concat(po.valuename, ':',
group_concat(po.value separator ',')) as taglie
from products p
right join products_opt po
on p.id = po.product
group by p.sku
) tbl
group by sku;
有什么建议吗? 谢谢
答案 0 :(得分:-1)
您需要为AUTO_INCREMENT
添加id
。
http://sqlfiddle.com/#!9/0bde6/2
select
p.sku,
sum(po.value = 'S') as `size S`,
sum(po.value = 'M') as `size M`,
sum(po.value = 'L') as `size L`,
po.product as demoproduct
from products p
right join products_opt po
on p.id = po.product
group by p.sku;
+-------+--------+--------+--------+-------------+
| sku | size S | size M | size L | demoproduct |
+-------+--------+--------+--------+-------------+
| PROD1 | 1 | 1 | 1 | 1 |
| PROD2 | 2 | 1 | 2 | 2 |
+-------+--------+--------+--------+-------------+