获取 Table 中的行 1 不匹配 Table 2 在多列上使用 JOIN

Getting the Rows in Table 1 That does not Match Table 2 Using JOIN on Multiple Columns

嗨,我有这样的查询:

 SELECT TT2.whs_code, 
        TT2.pdt_code, 
        TT2.fresh_frozen_status, 
        TT2.case_dt_yyyymmdd, 
        TT2.qty_cases, 
        TT2.qty_wt 
FROM #TempTable2 AS TT2 
LEFT OUTER JOIN #TempTable AS TT1 
    ON TT1.whs_code = TT2.whs_code 
    AND TT1.pdt_code = TT2.pdt_code 
    AND TT1.fresh_frozen_status = TT2.fresh_frozen_status 
    AND TT1.case_dt_yyyymmdd = TT2.case_dt_yyyymmdd

我想 select #TempTable2 中不存在的列基于

whs_code, pdt_code, fresh_frozen_status, case_dt_yyyymmdd 

意味着让我们说一组数据 1,115G,FR,20160222在#TempTable1 所以如果一组数据说
1,115G,FR,20160223 必须 selected 或
1,115G,FZ,20160223 必须 selected 或
2,115G,FR,20160223 必须 selected
但不是 1,115G,FR,20160222

我会使用 NOT EXISTS。

SELECT TT2.whs_code, 
    TT2.pdt_code, 
    TT2.fresh_frozen_status, 
    TT2.case_dt_yyyymmdd, 
    TT2.qty_cases, 
    TT2.qty_wt 
FROM #TempTable2 AS TT2 
WHERE NOT EXISTS (
                    SELECT TOP 1 *
                    FROM #TempTable AS TT1
                    WHERE tt1.whs_code = tt2.whs_code
                       AND tt1.pdt_code = tt2.pdt_code
                       AND TT1.fresh_frozen_status = tt2.fresh_frozen_status
                       AND TT1.case_dt_yyyymmdd  = TT2.case_dt_yyyymmdd 
                   )