SQL学习笔记——Operand should contain 1 column(s)
代码:select d.Name as Department,e.Name as Employee,e.Salaryfrom Department as d,Employee as ewhere d.Id=e.DepartmentIdand d.Id in (select max(Salary),Employee.DepartmentIdfrom Employeegroup by Departme
·
代码:
select d.Name as Department,e.Name as Employee,e.Salary
from Department as d,Employee as e
where d.Id=e.DepartmentId
and d.Id in (select max(Salary),Employee.DepartmentId
from Employee
group by DepartmentId);
报错:
Operand should contain 1 column(s)
原因:
在子查询中,查出的数据是有两个字段的,而where语句中,“ ... d.Id in ....”,只有一个字段进行查询。也就是说,前后的字段数量不匹配,在使用in谓词时,in左右两边的字段数量要相同。将上面的代码改成如下可以成功。
select d.Name as Department,e.Name as Employee,e.Salary
from Department as d,Employee as e
where d.Id=e.DepartmentId
and (e.Salary, d.Id) in (select max(Salary),Employee.DepartmentId
from Employee
group by DepartmentId);
更多推荐
已为社区贡献2条内容
所有评论(0)