views:

17

answers:

1

Am looking for a query to sum values in a particular time duration say an year or a particular month in an year using MySQL syntax. Note that my transaction_date column stores daily amount transacted.

Am example of a query that returns total sales in an year query would look something like this

SELECT SUM(transaction_amount) WHERE transaction_date = (YEAR)

Am example of a query that returns total sales in an particular month and year would look something like this

SELECT SUM(transaction_amount) WHERE transaction_date = (YEAR)(MONTH)

How achievable is this?

+4  A: 
SELECT SUM(transaction_amount)
WHERE YEAR(transaction_date) = '2008'
GROUP BY YEAR(transaction_date)

The second line may not be needed, depending on what you want exactly.

Coronatus