You may use cascading joins as follow, which can serve your purpose:

SELECT de_1.dept_name AS 'Department Name', 
       de_2.total_employee AS 'Total Employees', 
       eb.total_bonuses AS 'Total Bonuses'
FROM (

  SELECT d.dept_id, d.dept_name, e_1.emp_id 
  FROM departments d
  INNER JOIN employees e_1 ON e_1.emp_dept_id = d.dept_id

) AS de_1

INNER JOIN (
  SELECT d.dept_id, COUNT(e2.emp_id) AS total_employee
  FROM departments d
  INNER JOIN employees e2 ON e2.emp_dept_id=d.dept_id
  GROUP BY d.dept_id
) AS de_2 ON de_1.dept_id = de_2.dept_id

INNER JOIN (
  SELECT e3.emp_id, COUNT( b.bonus_id) AS total_bonuses
  FROM employees e3
  INNER JOIN bonuses b ON b.bonus_emp_id=e3.emp_id
  GROUP BY e3.emp_id
) AS eb ON eb.emp_id = de_1.emp_id; 

Posted in: MySQL

Related FAQ's

Marius Ion ANGEL HOT SOFT LLC (800) 316-7677