查询最低收入大于3700的部门信息:
下面是报错代码:
select d.EmployeeID from Salary d
where d.Income >
(select es.DepartmentID---错误在这里,MIN(es.Income) as minIncome from
(select s.*,e.DepartmentID from Employee e,Salary s
where e.EmployeeID = s.EmployeeID) as es
group by es.DepartmentID)
但改完有出现
子查询返回的值不止一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。
select d.EmployeeID from Salary dwhere d.Income >
(select MIN(es.Income) as minIncome from
(select s.*,e.DepartmentID from Employee e,Salary s
where e.EmployeeID = s.EmployeeID) as es
group by es.DepartmentID)
给出最终的解决方式
select L.DepartmentName,L.Note from
(select es.DepartmentID,MIN(es.Income) as minIncome from
(select s.*,e.DepartmentID from Employee e,Salary s
where e.EmployeeID = s.EmployeeID) as es
group by es.DepartmentID) as es2,Department L
where es2.minIncome > 3200 and L.DepartmentID= es2.DepartmentID