There is a funny trick that you can use when COUNT (column) counts the number of non-zero values; you also use self-connection (in doing so):
SELECT a.name, COUNT(b.name)
FROM mytable AS a LEFT OUTER JOIN mytable AS b
ON a.name = b.name AND b.status = 'A'
GROUP BY a.name;
This will work in all versions of SQL; not all options will allow you to summarize on a Boolean expression, which will undoubtedly be faster and more direct with its support.
Another way to write this:
SELECT a.name, COUNT(b.name)
FROM mytable AS a LEFT OUTER JOIN
(SELECT name FROM mytable WHERE status = 'A') AS b
ON a.name = b.name
GROUP BY a.name;
source
share