List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:August 16 2000 12:16am
Subject:Re: Need help with MySQL syntax query
View as plain text  
At 5:45 PM -0700 2000-08-15, Alvin Gani wrote:
>This is the first time I asked a question.  I have some problem executing a
>syntax for MySQL query.  Here's the situation.  I have Table A consisting
>two columns: Date (in standard format 2000-02-12), and amount (float).  I
>want to get a summary information on amount for a particular month.  Here's
>the "supposedly" query I want to have:
>Select sum(amount)
>from table
>where month = july/2000
>so I can get the result such as:
>Month		sum(amount)
>-----		-----------
>March		2300

Why do you want an output row for March when your query names July?

>What's the correct syntax for MySQL.  So far, I have tried the following:
>select entry_date, sum(amount)
>from transaction
>where monthname(entry_date)='March'
>group by entry_date
>But the results show:
>Month		sum(amount)
>------		-----------
>March		230
>March		130
>March		133
>March 	112

I don't think that's really what you're getting because if you select
entry_date you're going to get a date value in the first column, not

If you're trying to get a sum for a single month (e.g., March 2000),
all you need is:

SELECT SUM(amount) FROM transaction
WHERE YEAR(entry_date) = 2000 AND MONTH(entry_date) = 3;

If you want the March sum for each year separately, try:

SELECT YEAR(entry_date) AS y, MONTH(entry_date) AS m, SUM(amount)
FROM transaction
WHERE MONTH(entry_date) = 3
GROUP BY y, m;

Paul DuBois, paul@stripped
Need help with MySQL syntax queryAlvin Gani16 Aug
  • Re: Need help with MySQL syntax queryPaul DuBois16 Aug