I am trying to pull a query that will show me all my branches and how many reports they have open at any given time. I want to see 0 if they do not have any reports open. Here is my SQL:
What I would like to see are those branches that have 0 open records also.
Can anyone help with the SQL? I have tried may suggestions from the MySQL reference guide such as IFNULL, IS NULL and COALESCE.
Am I really dealing with NULL here or a 0 record count?
Any help would be outstanding!
Thanks,
David
Code:
SELECT DISTINCT branch_id, count(report_id) AS rptCount
FROM report_feeder
WHERE rpttype = 'report' AND report_status = 'open'
GROUP BY branch_id
ORDER BY branch_id;
+-----------+----------+
| branch_id + rptCount |
------------+-----------
|DIR + 1|
|EB1 + 1|
|EB2 + 18|
------------+-----------
What I would like to see are those branches that have 0 open records also.
Can anyone help with the SQL? I have tried may suggestions from the MySQL reference guide such as IFNULL, IS NULL and COALESCE.
Am I really dealing with NULL here or a 0 record count?
Any help would be outstanding!
Thanks,
David