WARNING: I am aware of this question -- It is NOT like mine because I added a GROUP BY
clause in my query and it is still not working.
I need to select the maximum value of the temporary column project_count
.
This is the query:
SELECT employee_id, COUNT(*) AS project_count FROM Employees WHERE project_level = 'L1' AND YEAR(Employees.project_date) = '2017' GROUP BY employee_id HAVING project_count = MAX(project_count);
If I remove the HAVING
clause, the output is like the following:
+-------------+---------------+
| employee_id | project_count |
+-------------+---------------+
| 1 | 2 |
| 2 | 1 |
| 3 | 3 |
| 5 | 1 |
+-------------+---------------+
However, if I include the HAVING
clause (which I need to use to know the maximum value of project_count
), the output is an empty set; but it should be like the following:
+-------------+---------------+
| employee_id | project_count |
+-------------+---------------+
| 3 | 3 |
+-------------+---------------+