All months, now.
November 15, 2007 1:28 PM
Subscribe
Sum of data for all months, including months with no rows, in MySQL?
Hi, I've come across this problem a few times, and here's the thing:
I'll do a query, for instance, SUM(distance) for each month, group by month. This'll give me results with the sum of distance for each month with rows. But I'd like to present the sums of all months, including non-active months. So far my only option seems to be to create an array of months in PHP, iterate through that, and, for each month, search for a result in the MySQL query result. This works, but is there a cleaner design pattern, or a MySQL trick that might come in handy?
Thanks for any help.
posted by tmcw to computers & internet (7 comments total)
posted by recursion at 1:45 PM on November 15, 2007