I need to find what bad with this SQL:
SELECT DepartmentName, COUNT(*)
FROM employee,department
WHERE employee.DepartmentID = department.DepartmentID
GROUP BY DepartmentName
WHERE COUNT(*)>1
I think the problem in COUNT(*)
beacause it return the count of all rows. So how I think the property sql will be without where statement. Help me I not good in SQL.
You have to use having cluase instead of where at the end of the statement:
SELECT DepartmentName, COUNT(*)
FROM employee,department
WHERE employee.DepartmentID = department.DepartmentID
GROUP BY DepartmentName
having COUNT(*)>1
SELECT DepartmentName, COUNT(*) AS count
FROM employee,department
WHERE employee.DepartmentID = department.DepartmentID
GROUP BY DepartmentName
HAVING count>1;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.