davykiash
davykiash

Reputation: 1804

Date problem in MYSQL Query

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?

Upvotes: 0

Views: 74

Answers (1)

Amy B
Amy B

Reputation: 17977

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.

Upvotes: 4

Related Questions