The sum of the acquisition price of works of art for each year (for example, if there were two works of art purchased for $1500 and $1000 in 2007, and one work of art purchased for $500 in 2008, then the sums would be $2500 and $500, for 2007 and 2008 respectively).
How to sum duplicated values in SQL
162 views Asked by BLACK PANTHER At
2
There are 2 answers
0
On
The keyword you're looking for is GROUP BY.
So your query will look something like
SELECT YEAR(date), SUM(price)
FROM tableName
GROUP BY YEAR(date)
Assuming your table contains a field containing the year, and a field containing the price, you would simply use:
If your table contains a date field, you'd need to extract the year from this field using the YEAR() function: