我收到错误消息“子查询返回多个值”,如何在我的情况下使用join来解决此问题
SELECT fdCI.INITIALPROCESSINGUSER,
fdCI.NEWUNDERWRITINGUSER,
fdCI.ISSUEPOLICYUSER,
fdR.REFERTOREASON,
fdR.PUTONHOLDREASON,
fdP.POLICYNUMBER,
fdP.INSUREDNAME,
p.WFSTATE,
p.WFLOCKTYPE ,
p.WFLOCKUSER,
p.WORKFLOWID,
p.WFWORKITEMID,
p.WFROUTINGTICKETID,
p.WFWORKSTEPNAME,
p.WFSTEPENTRYTIME,
p.WFPRIORSTEPNAME,
fdp.OWNERNAME,
fdR.REFERREDFROMUSERID,
fdp.CLIENTCODE,
p.WFFLOWENTRYTIME,
c.ACL,
fdp.PRODUCT,
PLANCODE
FROM PINewBusiness p,
CFPolicyCaseFolder c,
FDRounting fdR,
FDPolicyDetails fdP,
FDCaseInformation fdCI
WHERE (p.WFWORKSTEPNAME = 'ApproveQuote'
OR p.WFWORKSTEPNAME = 'ApprovalForm')
AND fdCI.AUTHORIZATIONUSER IS NULL
AND (fdR.NBAMOUNT <=
(SELECT cul.NBLIMIT
FROM FDNBUserAuthorization cua,
FDNBAuthorizationLevel cul
WHERE cua.NBAUTHORIZATIONID = cul.S_ROWID
AND cua.USER_ID = 'obaidats'
AND cul.NBTYPE= fdR.NBTYPE))
AND (c.CASEFOLDERID = SUBSTRING(p.CFREPKEY, 9, LEN(p.CFREPKEY)))
AND c.CASEFOLDERID=fdR.PARENT_CASEID
AND c.CASEFOLDERID=fdP.PARENT_CASEID
AND c.CASEFOLDERID=fdCI.PARENT_CASEID
AND (fdP.RAPIDUND IS NULL
OR fdP.RAPIDUND = 0)
答案 0 :(得分:0)
您可以检查下面的子查询的输出吗?
SELECT cul.NBLIMIT
FROM FDNBUserAuthorization cua,
FDNBAuthorizationLevel cul
WHERE cua.NBAUTHORIZATIONID = cul.S_ROWID
AND cua.USER_ID = 'obaidats'
AND cul.NBTYPE= fdR.NBTYPE
它肯定会返回多行,因为错误消息是不言自明的。现在,检查cul.NBLIMIT列中返回的值是多少?如果所有值都相同并且您可以保留其中任何一个,只需选择下面的TOP 1-
注意:
TOP 1适用于MSSQL Server, 对于MySQL和Oracle,您可以使用-LIMIT 1
SELECT TOP 1 cul.NBLIMIT
FROM FDNBUserAuthorization cua,
FDNBAuthorizationLevel cul
WHERE cua.NBAUTHORIZATIONID = cul.S_ROWID
AND cua.USER_ID = 'obaidats'
AND cul.NBTYPE= fdR.NBTYPE
但是,如果不同行中的值不同,则需要首先定义如何通过应用聚合器(如-SUM,MAX,MIN如下所示)将它们转换为一个值-
SELECT MAX(cul.NBLIMIT)
....
答案 1 :(得分:0)
对于此子查询,您应确保其返回的行不超过一个:
选择路线NBLIMIT 从FDNBUserAuthorization提示, FDNBAuthorizationlevel课程 在哪里cua.NBAUTHORIZATIONID = cul.S_ROWID AND cua.USER_ID ='obaidats' AND cul.NBTYPE = fdR.NBTYPE
从技术上解决此问题的两个选项
选择 MIN / MAX (cul.NBLIMIT) 从FDNBUserAuthorization提示, FDNBAuthorizationlevel课程 在哪里cua.NBAUTHORIZATIONID = cul.S_ROWID AND cua.USER_ID ='obaidats' AND cul.NBTYPE = fdR.NBTYPE
OR
选择路线NBLIMIT 从FDNBUserAuthorization提示, FDNBAuthorizationlevel课程 在哪里cua.NBAUTHORIZATIONID = cul.S_ROWID AND cua.USER_ID ='obaidats' AND cul.NBTYPE = fdR.NBTYPE WROWE ROWNUM = 1