GROUP BY MONTH(DateBilled) misses an entry consistently
| From: | Mike Gifford | Date: | Fri, 11 Jan 2002 08:12:55 +0000 |
| Subject: | GROUP BY MONTH(DateBilled) misses an entry consistently | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-15658@lists.php.net to get a copy of this message | ||
Hello
I've got the following SQL Query, which consistently pulls up only 3 out of 4 months from the database:
$sql = " SELECT COUNT(DateBilled) AS count, MONTH(DateBilled) AS BilledMonth, YEAR(DateBilled) AS BilledYear FROM Invoices GROUP BY MONTH(DateBilled) ORDER BY DateBilled ASC";
This results in:
Month: November Number of Invoices: 17
Month: December Number of Invoices: 22
Month: January Number of Invoices: 15
But when I do change the order of the query from ASC to DESC like this:
$sql = " SELECT COUNT(DateBilled) AS count, MONTH(DateBilled) AS BilledMonth, YEAR(DateBilled) AS BilledYear FROM Invoices GROUP BY MONTH(DateBilled) ORDER BY DateBilled ASC";$sql = " SELECT COUNT(DateBilled) AS count, MONTH(DateBilled) AS BilledMonth, YEAR(DateBilled) AS BilledYear FROM Invoices GROUP BY MONTH(DateBilled) ORDER BY DateBilled DESC";
I get:
Month: December Number of Invoices: 22
Month: November Number of Invoices: 17
Month: October Number of Invoices: 21
(I gained October and Lost January)
The date format in the DB is like this:
2001-12-05
I've tried a whole stack of variations on the above query, but I still seem to be coming up one short. Any idea why I'm not getting a display of all of the months?
Thanks.
Mike
--
Mike Gifford, OpenConcept Consulting, http://www.openconcept.ca
Supporting progressive organizations in online campaigns and tools.
Feature: Women's Learning Partnership http://learningpartnership.org
Truth is that which confirms what we already believe. Northrop Frye