将 NOT in 转换为 LEFT join 给出不正确的结果

问题描述

请帮助我将查询中的以下 NOT 转换为 Left join,因为我想要 select 子句中的日期列。我必须使用此查询作为 Amazon quicksight 的源。 Quicksight 无法将在报告中创建的日期参数传递给我的源查询。所以我必须在 WHERE 子句中获取日期过滤条件。

不在:

SELECT disTINCT Date(h.Created_Date) DATE,( h.Vehicle_ID)Decline
FROM awsdatacatalog.waves.Recurring_Transaction_History h  
Left JOIN awsdatacatalog.waves.Wash_Invoice wi  on h.invoice_id=wi.invoice_id

WHERE Date(h.Created_Date) BETWEEN date('2021-05-01') AND date('2021-05-01')

AND h.Status IN ('Declined','DECLINED')
AND h.Vehicle_ID NOT IN (
SELECT distinct ut.vehicle_Id
FROM awsdatacatalog.waves.Unlimited_Wash_Transaction ut 
WHERE   (Is_refunded IS NULL OR CAST(Is_refunded AS INTEGER) =0)
AND (Status ='RECURRING' or Status ='RESIGNUP')
AND DATE(DATE) BETWEEN date('2021-05-01') AND date('2021-05-01')
)

左连接查询

SELECT disTINCT Date(h.Created_Date) DATE,( h.Vehicle_ID)Decline
FROM awsdatacatalog.waves.Recurring_Transaction_History h  
Left JOIN awsdatacatalog.waves.Wash_Invoice wi  on h.invoice_id=wi.invoice_id
LEFT JOIN (
SELECT distinct ut.vehicle_Id,DATE(DATE) DATE
FROM awsdatacatalog.waves.Unlimited_Wash_Transaction ut 
WHERE   (Is_refunded IS NULL OR CAST(Is_refunded AS INTEGER) =0)
AND (Status ='RECURRING' or Status ='RESIGNUP')

) A
ON  H.Vehicle_ID = A.Vehicle_ID
AND  DATE(h.Created_Date) <= A.DATE
WHERE Date(h.Created_Date) BETWEEN date('2021-05-01') AND date('2021-05-01')
 AND A.Vehicle_ID IS NULL
 AND A.DATE IS NULL
AND h.Status IN ('Declined','DECLINED')
ORDER BY Date(h.Created_Date),( h.Vehicle_ID)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)