2015-06-02 41 views
0

这是我的表product_detailsMysql的SQL查询来格式化报告

Product_Code | Size | Quantity 
-------------+------+----------- 
CS01   | 10 | 15 
CS01   | 11 | 25 
CS01   | 12 | 35 
PR01   | 40 | 50 
PR01   | 41 | 60 

我想下面的报告,按产品代码来获取总量组格式(产品代码的所有尺寸) :

Product_Code | Size  | Quantity 
-------------+------------+---------------- 
CS01   | 10 11 12 | 75 
PR01   | 40 41  | 110 

我试过下面的查询,但它没有给出我想要的结果。

SELECT product_no, size, SUM(quantity) 
FROM product_details 
GROUP BY product_no; 

请帮我找到格式化报告的查询。

+0

使用'GROUP_CONCAT()'可以帮你)。 –

+0

非常感谢shA.t – Azmath

回答

2

您可以使用group concat

SELECT 
product_no, 
group_concat(size SEPARATOR ' '), 
sum(quantity) 
FROM product_details group by product_no; 
+0

非常感谢,您的查询帮助我解决了我的问题。 – Azmath