That's exactly what I'm looking for, thanks Eugene. :)
On Aug 5, 2005, at 12:46 AM, Eugene Kosov wrote:
Brian Dunning wrote:
I'm searching a table of people who own properties, and I want to
also include the total count of related properties, and the count
of related properties whose (status is 'Active' and approval is
'Active'). I've got:
select accounts.name, count(properties.property_id) as totalcount
from accounts, properties where
accounts.account_id=properties.account_id group by
accounts.account_id;
Works fine. Now I just need to figure out how to add that second
count of property records meeting the two conditions. Anyone?
I think query below should help you.
SELECT
accounts.name,
COUNT(properties.property_id) AS totalcount,
SUM(IF(status='Active' AND 'approval='Active', 1, 0))
FROM accounts LEFT JOIN properties USING(account_id)
GROUP BY accounts.account_id;
Regards,
Eugene Kosov
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?
[EMAIL PROTECTED]
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]