SELECT DISTINCT ACA.Application_No,AC.FirstName,AC.Id,AC.LastName,AC.MobileNo,CL.leadId
来自ABSLI_PAYMENT_TRANSACTION APT
在ACA.Policy_No = APT.policyId上内部加入ABSLI_CUSTOMER_APPLICATION ACA
内联接ABSLI_CUSTOMER AC ON AC.Id = ACA.CustomerId
左联接ABSLI_CUSTOMER_LEAD CL ON CL.policyId = ACA.Policy_No
内连接ABSLI_Policy_Status_Tracking pst ON pst.policyId = APT.policyId
APT.paymentStatus ='Y'
不存在(从ABSLI_SERVICE_STATUS WHERE PolicyNo = APT.policyId和NAME ='APEX_Validate'中选择1)
和ACA.Application_No NOT IN(从ABSLI_REFUND_TRANSACTION RT中选择RT.ApplicationNumber,其中RT.Status!='保留')
ORDER BY pst.updatedDate DESC;
最佳答案
相关子查询在较大的数据集上可能会耗资巨大,您可能需要尝试进行转换
...
AND NOT EXISTS (SELECT 1 FROM ABSLI_SERVICE_STATUS WHERE PolicyNo=APT.policyId AND NAME = 'APEX_Validate')
...
像
...
LEFT JOIN ABSLI_SERVICE_STATUS AS ss ON APT.policyId = ss.PolicyNo AND ss.NAME = 'APEX_Validate'
...
AND ss.NAME IS NULL
通常,我建议从
ss
的“ id”字段进行IS NULL检查,但是NAME
显然存在(根据您的查询),并且不能同时为'APEX_Validate'和NULL。另外,如果PolicyNo, Name
上有复合索引,则可以在不访问表本身的情况下使用该索引。)