ID的DISTINCTROW

时间:2012-12-10 01:54:40

标签: mysql

enter image description here

选择 DISTINCTROW ProductsId AS pid,(SELECT SUM(QuantityByID)WHERE ProductsId = pid) 从 cartitem

我想得到这个结果

ProductId Quantity 
7             7 
13            2 
14            2 
9             1 

1 个答案:

答案 0 :(得分:0)

没有问题很难提供帮助,但我认为你想要一个GROUP BY:

SELECT ProductsId as pid, SUM(QuantityByID) 
FROM products
GROUP BY ProductsId

这将给出每个产品ID的数量总和。