当我进行子查询时,我有问题
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列,为什么?
发布于 2016-04-25 04:41:57
使用联接而不是子查询。此外,您的子查询可能返回多于1行,因此它会显示错误。为了避免对每个select的错误使用限制(这不是最好的解决方案),在这种情况下,它只返回第一行。
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'https://stackoverflow.com/questions/36831798
复制相似问题