当没有用 EXISTS 引入子查询时,在选择列表中只能指定一个表达式。

查询最低收入大于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 d
where 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值