Using GROUP BY problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
avmohankumar
Forum Newbie
Posts: 14
Joined: Fri Jun 08, 2007 7:20 am

Using GROUP BY problem

Post by avmohankumar »

Dear Friends,

I want to sum up the field 'B'. By using this query

$query = SELECT SUM(B) AS A FROM `maza` WHERE DATE = 2007-06-06 GROUP BY DATE

But this is not working.


In that 'maza' tables are having two record on the date 2007-06-06. I want to sum up the value which date are group by same date.


Please suggest me,

Thanks in advance.

Regards,
Maza
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Put quotes around date value.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Moved to "Databases" forum.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Using GROUP BY problem

Post by califdon »

avmohankumar wrote:

Code: Select all

$query = SELECT SUM(B) AS A FROM `maza` WHERE DATE = 2007-06-06 GROUP BY DATE
If you're going to use just one date, then it makes no sense to GROUP BY date. However, if you are really going select on multiple dates, then it would.
User avatar
xpgeek
Forum Contributor
Posts: 146
Joined: Mon May 22, 2006 1:45 am
Location: Kyiv, Ukraine
Contact:

Post by xpgeek »

DATE is reserved word.
Quote it or change field name.
Post Reply