仅显示与控件不匹配的行 table

Display only rows that do not match the control table

我目前遇到了一个问题,因为我无法真正用语言解释它,如果我在这里进行测试 table 会更好。

Table1:

Source_DB   Source_TBL   Source_Col   Target_DB   Target_TBL   Target_Col   Metric   Source_VAL   Target_Val
____________________________________________________________________________________________________________
Source_D    Source_T     Col1         Target_D    Target_T     Col1         Index    1            1
Source_D    Source_T     Col1         Target_D    Target_T     Col1         Length   10           10
Source_D    Source_T     Col1         Target_D    Target_T     Col1         Scale    4            4

对照Table:

DB_NM      TBL_NM    COL_NM    METRIC    INCLUDE_FLAG
_____________________________________________________
Source_D   Source_T  Col1      Length    N

现在在控件 table 中,由于包含标志为 N,因此不应包含与 DB_NM、TBL_NM、COL_NM 匹配的行 Table1。我尝试使用 NOT IN(subquery) 但是我失败了,因为我正在比较许多列。 EXISTS 也是不允许的,因为控件 table 中的列与 Table1 中的列不匹配。这个有什么解决方法吗? 结果应该是:

 Source_DB   Source_TBL   Source_Col   Target_DB   Target_TBL   Target_Col   Metric   Source_VAL   Target_Val
____________________________________________________________________________________________________________
Source_D    Source_T     Col1         Target_D    Target_T     Col1         Index    1            1
Source_D    Source_T     Col1         Target_D    Target_T     Col1         Scale    4            4

NOT EXISTS解决方案。您可能需要在子查询的 WHERE:

中添加一些条件
select t1.*
from table1 t1
where NOT EXISTS (select 1 from ControlTable ct
                  where t1.Source_DB = ct.DB_NM
                    and t1.Source_TBL = ct.Source_TBL
                    ...
                    and ct.INCLUDE_FLAG = 'N')

(即 ... 应被删除,或替换为附加条件。)

select SOURCE_DB, SOURCE_TBL, SOURCE_COL, TARGET_DB, Target_TBL, Target_Col, Metric, Source_VAL, Target_Val
from dummy_temp
where metric not in (select metric from dummy_control);