user382538
user382538

Reputation:

mysql query sum based on years

i friend i have a database table

amount_id, year, amount,

and data like this

1 2002 2
2 2002 3
3 2007 2
4 2004 6
5 2004 10

i wan to run a query to select data like this

2002 4
2007 2
2004 16

thanks for help

Upvotes: 0

Views: 111

Answers (2)

Marc B
Marc B

Reputation: 360562

SELECT `year`, SUM(amount)
FROM databasetable
GROUP BY `year`

Should be all you need.

Upvotes: 1

Kris.Mitchell
Kris.Mitchell

Reputation: 998

It looks like you need to use a sum(amount) in your select statement and group by year after your where.

Upvotes: 0

Related Questions