我制作子查询时遇到问题
select r.Request_ID,
(
(select e.ReportsTo, (select e1.FirstName from Employees e1 where e1.NIK = e.ReportsTo) as FirstName,
(select e1.NIK from Employees e1 where e1.NIK=e.NIK) as Attention,
(select e1.FirstName from Employees e1 where e1.NIK=e.NIK) as AttentionName
from Employees e where e.ReportsTo ='CS-NIK-2016-0150' and e.NIK='CS-NIK-2016-0160')
)
from Request r where r.Request_ID='CS-REQ-BDG-201604-10099'

操作数应包含1列,为什么?
答案 0 :(得分:0)
使用join而不是子查询。您的子查询也可能返回超过1行,因此它显示错误。 为了避免错误使用限制,每个选择都不是最佳解决方案,因为在这种情况下它将只返回第1行。
select r.Request_ID,
(
(select e.ReportsTo, (select e1.FirstName from Employees e1 where e1.NIK = e.ReportsTo limit 1) as FirstName,
e.NIK as Attention, FirstName as AttentionName
from Employees e where e.ReportsTo ='CS-NIK-2016-0150' and e.NIK='CS-NIK-2016-0160')
)
from Request r where r.Request_ID='CS-REQ-BDG-201604-10099'