我必须找到员工人数最多的部门的名称和国家。
SELECT d.department_name, c.country_name FROM employees e, departments d, locations l, countries c
WHERE d.location_id = l.location_id AND l.country_id = c.country_id
HAVING MAX(e.employee_id) = (SELECT MAX(MAX(employee_id)) FROM employees GROUP BY department_id);
我得到的不是单组组功能错误。那是为什么?
答案 0 :(得分:1)
如果没有错,这就是你要找的东西
SELECT *
FROM (SELECT d.department_name,
c.country_name
FROM employees e
INNER JOIN departments d
ON e.department_id = d.department_id
INNER JOIN locations l
ON d.location_id = l.location_id
INNER JOIN countries c
ON l.country_id = c.country_id
GROUP BY d.department_name,
c.country_name
ORDER BY Count(1) DESC)
WHERE ROWNUM = 1
答案 1 :(得分:0)
这就是你想要的吗?
SELECT d.department_name, c.country_name FROM employees e, departments d, locations l, countries c
WHERE d.location_id = l.location_id AND l.country_id = c.country_id
AND ROWNUM = 1
ORDER BY e.employee_id DESC