Re: COUNT() - returning rows with 0 value
Merlin <ngroups@fastmail.fm> wrote in
<5rsm8pF16aufeU1@mid.individual.net>:
> Now:
> 1 = 400
> 3 = 192
>
> Should be:
> 1 = 400
> 2 = 0
> 3 = 192
You didn't provide an actual sample dataset and resulting
rows, but at a guess, you'll need a LEFT JOIN. Read about
LEFT JOINs in MySQL Reference Manual.
> SELECT
> count(*) AS ct,
> group_name,
> group_id
> FROM
> user u,
> age_description ad
> WHERE
> points >= 5000
> AND
> ad.group_id = u.age
> GROUP BY
> ad.group_id
> ORDER BY
> group_id
Note that you'll need to modify your aggregate expression as
well, since what you need to count are users, not rows.
--
....also, I submit that we all must honourably commit seppuku
right now rather than serve the Dark Side by producing the
HTML 5 spec. |