GROUP BY MONTH() Error

Codes here !

Moderators: egami, macek, gesf

Post Reply
MeroD
New php-forum User
New php-forum User
Posts: 53
Joined: Wed Oct 10, 2012 12:14 am

Tue Nov 06, 2012 11:59 pm

$query = "SELECT MONTH(EXPDATE),SUM(ORDTOTAL) ";
$query .= "FROM OEORDH ";
$query .= "WHERE TYPE='1' AND ORDTOTAL>'0' ";
$query .= "GROUP BY MONTH(EXPDATE)";

MeroD
New php-forum User
New php-forum User
Posts: 53
Joined: Wed Oct 10, 2012 12:14 am

Fri Nov 09, 2012 11:50 pm

Try: GROUP BY YEAR(EXPDATE), MONTH(EXPDATE)

Or: DATE_FORMAT('EXPDATE`, '%M')

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Tue Nov 13, 2012 1:30 pm

You're having issues because you're pulling a scalar value, and grouping on an aggregate. Change your select to read '$query = "SELECT MONTH(EXPDATE),SUM(ORDTOTAL) ";' etc, and you should be fine, except that you're probably going to have bad data if you have data for 11/11 and 11/12. so you could select and group by YEAR(EXPDATE),MONTH(EXPDATE). You also don't need to include your sum(ORDTOTAL) in the group by.

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests