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后面,然后通过'='作条件过滤。

问题原因,暂且未知。

 

posted on 2018-08-31 18:06  IDVD  阅读(593)  评论(0编辑  收藏  举报

导航