正确使用如下:
SELECT dep.department_name, MAX(emp.salary), MIN(emp.salary)
FROM departments dep
LEFT JOIN employees emp
ON (dep.department_id = emp.department_id)
GROUP BY dep.department_name
--order by 的列,必须是出现在group by 子句里的列
ORDER BY dep.department_name DESC
错误使用如下:
(执行后报错:ORA-00979:不是GROUP BY 表达式)
SELECT dep.department_name, MAX(emp.salary), MIN(emp.salary)
FROM departments dep
LEFT JOIN employees emp
ON (dep.department_id = emp.department_id)
GROUP BY dep.department_name
--order by 的列,应该出现在group by 子句中
ORDER BY dep.department_id DESC