[plug] Optimise MySQL query
nigel at dubh.id.au
nigel at dubh.id.au
Thu Mar 30 10:36:36 WST 2006
Hi all,
On Wed, Mar 29, 2006 at 10:40:56AM +0800, Ryan King wrote:
>
> SELECT count(*), DATE_FORMAT(date, '%Y-%m') as month
> FROM $table
> WHERE user=$user
> GROUP BY month
I'm using this code of Ryan's and it is working a treat. However
it (obviously) doesn't return values for months where the user
isn't in the table for that month. So to be clear we get return
values like this;
month: 01 count: 5
month: 02 count: 4
month: 03 count: 9
month: 11 count: 6
month: 12 count: 4
Now I can assign those values to variables and check each month to
see if it is defined. I was wondering if it wouldn't be better to
have mysql just return a zero. Can the query be structured like
this?
Many thanks
Nigel
More information about the plug
mailing list