Michael Müller
Michael Müller

Reputation: 401

SQL Select add up rows

I want to select an add up simular rows bases on one field

product    amount
abc        2
abc        3
def        2
def        1

and I want as a result

Produkt    Amount
abc        5
def        3

Any ideas?

Upvotes: 0

Views: 73

Answers (2)

Jamie Babineau
Jamie Babineau

Reputation: 766

You need to group the table by the product and then select the name and use the aggragate function of SUM. Your query for this should look something like this:

SELECT product, SUM(amount) 
FROM <TABLENAME>
GROUP BY product

Upvotes: 1

potashin
potashin

Reputation: 44601

Use sum aggregate function with the group by clause:

select product, sum(amount) from tbl group by product

Upvotes: 4

Related Questions