SQLTeam.com | Weblogs | Forums

Selecting Departments With More Than 10,000 Female Employees

I have this so far which would be almost right

My select query is:

SELECT dept_name,
COUNT(*) AS female_count from employees
LEFT JOIN dept_emp
ON employees.emp_no = dept_emp.emp_no
LEFT JOIN departments
ON departments.dept_no = dept_emp.dept_no
WHERE employees.gender = 'F'
GROUP BY 1
ORDER BY 2 DESC;

I need the first three rows specifically and havent included our condition where number of female employees is greater than 10,000

I am getting an error when trying to use that count(*) or total number of female employees is greater than 10,000 with my where clause, this:

WHERE employees.gender = 'F' AND COUNT(*) > 10000

I was thinking of doing limit 3 below that doesnt satisfy number of employees is greater than 10,000 the right way still i need some feedback

In an aggregate query - you need to use HAVING clause to evaluate the results after the grouping.