SQL simple -> Write condition in WHERE clause instead of HAVING if possible



Try to see whether you really need to write condition in HAVING clause. The task is to count female employees per Department:
SELECT a.DeptNo, b.DeptName, count(*) AS cn
FROM Employees AS a INNER JOIN Departments AS b
ON a.DeptNo = b.DeptNo
GROUP BY a.DeptNo, b.DeptName
HAVING a.Gender = 'F';

/* condition Gender='F' can easely move to WHERE */

SELECT a.DeptNo, b.DeptName, count(*) AS cn
FROM Employees AS a INNER JOIN Departments AS b
ON a.DeptNo = b.DeptNo
WHERE a.Gender = 'F'
GROUP BY a.DeptNo, b.DeptName;


sqlexamples.info