MySQL:如果行相等则求和

时间:2014-11-27 10:46:04

标签: mysql sql sum equals

我想创建一个SQL select-query来选择所有内容,但是当clientthicknessmaterial相同时,它们的值为' amount'应该加上。

我如何创建这样的查询?

data sample

2 个答案:

答案 0 :(得分:6)

如果我理解正确的话。你可以这样做:

SELECT
    client, 
    thickness,
    material,
    SUM(amount) AS TotalAmount
FROM
    Table1
GROUP BY
    client, 
    thickness,
    material 

答案 1 :(得分:1)

如果是同一列

SELECT
   SUM(amount) AS Total
FROM
    Tablename
GROUP BY
    client, 
    thickness,
    material