根据另一个 table 中的条件组合识别行是否有效
Recognise if row is Valid based on combination of conditions in another table
我有 table Inbound
约 200 万条记录,具有以下结构
Inbound table
ID campaign_id Entry_status Error_code
A1 1234 0 0
B1 1234 -1 -1
C1 4123 0 -15
C1 4123 0 0
我还有一个 table Rules
,它是 Entry_status
和 Error_code
的所有组合的列表,表示 valid Inbound
table
中的条目
Rules table
campaign_id Entry_status Error_code
1234 0 0
4123 0 -15
我正在尝试创建一个查询,该查询将允许我根据 [=17= 中的 Entry_status
和 Error_code
的组合列出有效的 Inbound
中的所有条目]
到目前为止我已经想到了这个,但它只给我无效的条目,我也怀疑它是错误的。
SELECT * FROM Inbound
WHERE ID not IN (
SELECT ID FROM Inbound JOIN Rules
on Inbound.campaign_id= Rules.campaign_id
where Inbound.Entry_status = Rules.ENTRY_STATUS
and
Inbound.Error_code = Rules.Error_code
)
感觉我需要嵌套另一个查询来考虑 2 列的组合以生成有效条目?
查看了 this 并且这没有帮助,因为验证标准是一个字符串,而不是列的组合
................................
奖金
是否可以在 ìnbound
中添加 true / false 字段,表示根据 rules
中的规则组合,记录是否 valid
我可以运行
Update Inbound I
SET I.valid = if(**select function** = True , 1 ,0 )
所以 Inbound 标记了有效和无效条目,而不仅仅是另一个 table
Select 函数由 underscore-d
提供
select distinct Inbound.*
from Inbound
inner join Rules on
Inbound.campaign_id = Rules.campaign_id
Where
Inbound.Entry_status = Rules.Entry_status and
Inbound.Error_code = Rules.Error_code;`
select distinct Inbound.*
from Inbound
inner join Rules on
Inbound.campaign_id = Rules.campaign_id
where -- or adding these conditions to the INNER JOIN would be the same
Inbound.Entry_status = Rules.Entry_status and
Inbound.Error_code = Rules.Error_code;
...或者只是将您的 not in
更改为 in
,因为您的理解方式完全错误!虽然那个嵌套版本看起来比这个更复杂。
我有 table Inbound
约 200 万条记录,具有以下结构
Inbound table
ID campaign_id Entry_status Error_code
A1 1234 0 0
B1 1234 -1 -1
C1 4123 0 -15
C1 4123 0 0
我还有一个 table Rules
,它是 Entry_status
和 Error_code
的所有组合的列表,表示 valid Inbound
table
Rules table
campaign_id Entry_status Error_code
1234 0 0
4123 0 -15
我正在尝试创建一个查询,该查询将允许我根据 [=17= 中的 Entry_status
和 Error_code
的组合列出有效的 Inbound
中的所有条目]
到目前为止我已经想到了这个,但它只给我无效的条目,我也怀疑它是错误的。
SELECT * FROM Inbound
WHERE ID not IN (
SELECT ID FROM Inbound JOIN Rules
on Inbound.campaign_id= Rules.campaign_id
where Inbound.Entry_status = Rules.ENTRY_STATUS
and
Inbound.Error_code = Rules.Error_code
)
感觉我需要嵌套另一个查询来考虑 2 列的组合以生成有效条目?
查看了 this 并且这没有帮助,因为验证标准是一个字符串,而不是列的组合
................................
奖金
是否可以在 ìnbound
中添加 true / false 字段,表示根据 rules
valid
我可以运行
Update Inbound I
SET I.valid = if(**select function** = True , 1 ,0 )
所以 Inbound 标记了有效和无效条目,而不仅仅是另一个 table
Select 函数由 underscore-d
提供select distinct Inbound.*
from Inbound
inner join Rules on
Inbound.campaign_id = Rules.campaign_id
Where
Inbound.Entry_status = Rules.Entry_status and
Inbound.Error_code = Rules.Error_code;`
select distinct Inbound.*
from Inbound
inner join Rules on
Inbound.campaign_id = Rules.campaign_id
where -- or adding these conditions to the INNER JOIN would be the same
Inbound.Entry_status = Rules.Entry_status and
Inbound.Error_code = Rules.Error_code;
...或者只是将您的 not in
更改为 in
,因为您的理解方式完全错误!虽然那个嵌套版本看起来比这个更复杂。