0

の役割を"PPC"持ち、"paygroups"それらの PPC が属するすべての電子メールを出力することを目的としたクエリがあります。

  • 多くの支払いグループがあります。
  • それぞれpaygroupに複数の を含めることができますPPCs
  • それぞれPPCemail address 1および/または がありemail address 2ます。

テストを使用するとクエリは正常に機能paygroup(BOX)しますが、その行をコメントアウトしてすべてをクエリしてすべてをpaygroups返すと、エラーが発生します。PPCspaygroups"single-row subquery returns more than one row"

SELECT
auth.paygroup,
per.NAME, 
per.email_address AS    "Personal email",
per.email_address2 AS   "Business email"

FROM ps_personal_data per 

INNER JOIN ps_ts_ee_auth auth 
ON auth.emplid=per.emplid

INNER JOIN PS_SMS_SUBSCRB_TBL SUB
ON SUB.SUBSCRIBER_ID = AUTH.PAYGROUP

WHERE 1=1    
 AND SUB.EFFDT = (SELECT max (SUB2.effdt) FROM PS_SMS_SUBSCRB_TBL SUB2 
   WHERE SUB.SUBSCRIBER_ID = SUB2.SUBSCRIBER_ID AND SUB.EFF_STATUS = 'A')  
 AND auth.user_name = (SELECT R1.USER_NAME FROM PS_TS_CONTACT_ROLE R1
                      WHERE 1=1
                      AND R1.contact_role = 'PPC'
                    --AND R1.paygroup = 'BOX' --commenting this line out causes the error. It works fine when line is active
                      AND R1.action_dt = (SELECT MAX (R2.action_dt) 
                                         FROM PS_TS_CONTACT_ROLE R2
                                         WHERE 1=1
                                         AND R1.paygroup = R2.paygroup
                                         AND R1.contact_role =                                   
                                         R2.contact_role))
4

1 に答える 1

1
SELECT
auth.paygroup,
per.NAME, 
per.email_address AS    "Personal email",
per.email_address2 AS   "Business email"

FROM ps_personal_data per 

INNER JOIN ps_ts_ee_auth auth 
ON auth.emplid=per.emplid

INNER JOIN PS_SMS_SUBSCRB_TBL SUB
ON SUB.SUBSCRIBER_ID = AUTH.PAYGROUP

WHERE 1=1    
 AND SUB.EFFDT = (SELECT max (SUB2.effdt) FROM PS_SMS_SUBSCRB_TBL SUB2 
   WHERE SUB.SUBSCRIBER_ID = SUB2.SUBSCRIBER_ID AND SUB.EFF_STATUS = 'A')  
 AND auth.user_name in (SELECT R1.USER_NAME FROM PS_TS_CONTACT_ROLE R1 -- Change = to in
                      WHERE 1=1
                      AND R1.contact_role = 'PPC'
                      AND R1.paygroup = 'BOX' --commenting this line out causes the error. It works fine when line is active
                      AND R1.action_dt = (SELECT MAX (R2.action_dt) 
                                         FROM PS_TS_CONTACT_ROLE R2
                                         WHERE 1=1
                                         AND R1.paygroup = R2.paygroup
                                         AND R1.contact_role =                                   
                                         R2.contact_role))
于 2016-10-25T13:29:48.477 に答える