【发布时间】:2017-12-14 13:14:24
【问题描述】:
mysql中的select是这样的:
SELECT v.product_id,
nome AS Produto,
presentation AS Descricao,
presentation AS Descricao2,
name1 AS categoria,
description_two AS descricao,
price AS preco,
quantity AS estoque,
width,
height,
depth,
weight,
name,
referencecode,
datapostagem
FROM variant v
INNER JOIN productcategory p
ON v.product_id = p.product_id
INNER JOIN product
ON product.id = p.product_id
INNER JOIN category
ON category.id = category_id
INNER JOIN image i
ON i.product_id = p.product_id
INNER JOIN descriptiongroup D
ON D.product_id = p.product_id
INNER JOIN stock S
ON S.variant_id = v.id
INNER JOIN dimensiongroup G
ON G.variant_id = v.id
LIMIT 10
结果返回大量重复的product_id,如何将product_id 分隔在另一列中?比如product2,product3,product4?
如果我这样做,它会向我显示正确的表单,但只针对一个结果,我如何在我的主选择中加入下面的这个选择?
select
product_id,
sum(case when presentation = 'Unitário = R$ 11,90 ' THEN price END) product_id1,
sum(case when presentation = '5 Peças = R$ 5,00 cada' THEN price END) product_id2,
sum(case when presentation = 'Bluesky Todas' THEN price END) product_id3
from
Variant
where
product_id = 1604
结果是:
product_id product_id1 product_id2 product_id3
1604 11.9 25 15
我怎样才能让它变得动态,让我看到所有的结果,而不仅仅是一个?
结果如下图:
【问题讨论】:
-
显示示例输入以及期望与预期的输出。
-
我希望在结果中像 , product_id2, product_id3, product_id4 这样在选择结果中显示重复的 product_id
-
添加一些示例表数据和预期结果。作为格式化文本,而不是图像。
-
考虑阅读stackoverflow.com/help/mcve 以获得更好的答案,更快!
-
我编辑,看那里,我在这个问题上两天了,请帮忙
标签: sql