mysql - How to sum duplicated values in SQL -


the sum of acquisition price of works of art each year (for example, if there 2 works of art purchased $1500 , $1000 in 2007, , 1 work of art purchased $500 in 2008, sums $2500 , $500, 2007 , 2008 respectively).

assuming table contains field containing year, , field containing price, use:

select acquisitionyear, sum(price) totalprice mytable group acquisitionyear 

if table contains date field, you'd need extract year field using year() function:

select year(acquisitiondate), sum(price) totalprice mytable group year(acquisitiondate) 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -