数据库 - 使用 group by 而不对结果进行分组
Database - Using group by without grouping result
我有一个 table 这样的:
Product_ID | Size_ID
3 | S
3 | M
4 | L
5 | S
我希望结果如下:
Product_ID | Size_ID
3 | M, S
4 | L
5 | S
可以吗?我的查询是这样的:
Select Product_ID, Size_ID
FROM product
Group by Product_ID
Order by Product_ID Desc
尝试 group_concat:
Select Product_ID, GROUP_CONCAT(Size_ID)
FROM product
Group by Product_ID
Order by Product_ID
group_concat
函数应该可以解决问题:
Select Product_ID, GROUP_CONCAT(Size_ID ORDER BY Size_ID)
FROM product
Group by Product_ID
Order by Product_ID Desc
我有一个 table 这样的:
Product_ID | Size_ID
3 | S
3 | M
4 | L
5 | S
我希望结果如下:
Product_ID | Size_ID
3 | M, S
4 | L
5 | S
可以吗?我的查询是这样的:
Select Product_ID, Size_ID
FROM product
Group by Product_ID
Order by Product_ID Desc
尝试 group_concat:
Select Product_ID, GROUP_CONCAT(Size_ID)
FROM product
Group by Product_ID
Order by Product_ID
group_concat
函数应该可以解决问题:
Select Product_ID, GROUP_CONCAT(Size_ID ORDER BY Size_ID)
FROM product
Group by Product_ID
Order by Product_ID Desc