max()———select后————过滤条件
-----------------------------------------------------------------------------------这是一条分割线-----------------------------------------------------------------------------------------
我的sql是:
SELECT d.`Name` department,e.`Name` Employee,MAX(e.Salary) Salary FROM employee e,department d WHERE e.DepartmentId=d.Id GROUP BY department;
查出:
明显,工资的人名对不上!!!
参考sql为:
select d.Name as Department,e.Name as Employee,e.Salary from Department d,Employee e
where e.DepartmentId=d.Id and e.Salary=(Select max(Salary) from Employee where DepartmentId=d.Id);
把max的过滤功能放到where后面,然后通过'='作条件过滤。
问题原因,暂且未知。