2013-12-16 35 views
-3

我想这个一些想法的和值:MySQL的 - 同样的产品

product_id || tag_id || weight 
-------------------------------- 
4   || 7  || 5 
3   || 7  || 5 
3   || 7  || 5 
3   || 6  || 3 
2   || 4  || 2 
2   || 6  || 3 
1   || 4  || 2 

我需要这样的东西: product_x总重量= Y,使用MySQL。

的行动应该是:

if product_id[rowN] == product_id[rowN+1] 
then sum(weight[rowN] + weight[rowN+1] 

我试图谷歌,荷兰国际集团,但无法找到任何工作。

感谢

回答

0
select product_id, sum(weight) FROM table GROUP BY product_id