Re: counting multiple columns based on different values
| From: | John Hawkins | Date: | Fri, 15 Feb 2002 16:05:13 +0000 |
| Subject: | Re: counting multiple columns based on different values | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-16979@lists.php.net to get a copy of this message | ||
Peter,
I totally appreciate the extra effort on this one!
Just so you know, the results come back as two records
per client. Like this:
| ClientName | Status | Count |
| Steve | 2 | 25 |
| Steve | 3 | 83 |
| Gary | 2 | 12 |
| Gary | 3 | 33 |
This is close enough to the solution I was looking for
that I can proceed from here!
Thanks a million!
John
>OK, this time tested :)
>
>SELECT Clients.ClientName, Ratings.Status, Count(*)
FROM Clients LEFT
>JOIN
>Ratings ON Clients.ID = Ratings.ClientID
>GROUP BY ClientName, Ratings.Status
>HAVING Ratings.Status = 2 OR Ratings.Status = 3
>
>regards,
>
>Peter
>Software Engineer / Trainer
>Vervoorn IT
>----- Original Message -----
>From: "Peter Vervoorn" <maillist@vervoorn.com>
>To: "php-db list" <php-db@lists.php.net>
>Sent: Thursday, February 14, 2002 9:36 AM
>Subject: Re: [PHP-DB] counting multiple columns based
on different
>values
>
>
>> This should do the trick (untested):
>>
>> SELECT ClientName, Count(*) FROM Clients LEFT JOIN
Ratings ON
>Clients.ID =
>> Ratings.ClientID
>> GROUP BY ClientName
>> HAVING Ratings.Status = 2 OR Ratings.Status = 3
>>
>>
>> regards,
>>
>> Peter
>> Software Engineer / Trainer
>> Vervoorn IT
__________________________________________________
Do You Yahoo!?
Got something to say? Say it better with Yahoo! Video Mail
http://mail.yahoo.com