总结一下

时间:2016-12-19 04:33:33

标签: postgresql

我有一张这样的表:

Count        Product
100         apple
50          apple
20          orange

如何选择获得每件产品的总和?

Count         Product
150           apple
20           orange

2 个答案:

答案 0 :(得分:0)

使用SUM(),

尝试查询
 select SUM(count) as count,Product from #YourTable
 group by Product

SUM()函数返回数字列的总和

答案 1 :(得分:0)

您应该使用聚合函数:

    select SUM(count) as Count, Product from Product
    group by Product