Stefan
Stefan

Reputation: 1895

MySQL: Sum if rows are equal

I want to make a SQL select-query to select everything, but when the client, thickness and material are the same their value of 'amount' should be added.

How would I go about creating such a query?

data sample

Upvotes: 0

Views: 1078

Answers (2)

Imran Qamer
Imran Qamer

Reputation: 2265

if same column then

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

Upvotes: 1

Arion
Arion

Reputation: 31239

If I understand you correctly. You could do something like this:

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

Upvotes: 6

Related Questions