you lost me right here --
from
ost_ticket
left join ost_staff on ost_ticket.staff_id = ost_staff.staff_id
since it's a left outer join, this returns every ticket, regardless of whether there's a staff related to a ticket
in other words, your tickets have missing or invalid staffs
similarly, your tickets have missing or invalid departments
if this is not the case, make them INNER JOINs
the good news is, you can use SUM() and COUNT() on CASE expressions, and your three queries are easy to combine since they have the same FROM and GROUP BY clauses