You can use sum
with case
and move the subquery to the where
criteria:
select
sum(case when status = 'new' then 1 else 0 end) new,
sum(case when status = 'processing' then 1 else 0 end) processing,
sum(case when status = 'close' then 1 else 0 end) close
from tickets
where id_client in (_a_list_of_client_id)
There are a couple other ways to do this (using if
for example or leaving out the case
), but I think this is easy to read. I believe mysql will work with sum(status='new')
for example.