SQL查询在同一列上使用In和Not In子句,我想以不同的方式重写下面的查询。 [英] SQL Query using In and Not In clause on the same column ,i want to re write below query in different way.
本文介绍了SQL查询在同一列上使用In和Not In子句,我想以不同的方式重写下面的查询。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SELECT LM.eCPPatientDMG_Key FROM tbl_eCPLedger_Master LM
WHERE LM.eCPLedger_Payer_Key IN
(SELECT LP.eCPLedger_Payer_Key FROM tbl_eCPLedger_Payer LP WHERE UPPER(LP.eCPLedger_Payer_ID) = 'SELF' )and LM.eCPAccount_Key='0481843194'
AND LM.eCPLedger_Payer_Key NOT IN
(SELECT LM1.eCPPatientDMG_Key FROM tbl_eCPLedger_Master LM1
WHERE LM1.eCPLedger_Payer_Key IN
(SELECT LP1.eCPLedger_Payer_Key FROM tbl_eCPLedger_Payer LP1 WHERE UPPER(LP1.eCPLedger_Payer_ID) <> 'SELF' )and LM1.eCPAccount_Key='0481843194')
推荐答案
Tr this:
Tr this:
SELECT LM.eCPPatientDMG_Key
FROM tbl_eCPLedger_Master LM INNER JOIN tbl_eCPLedger_Payer LP ON LM.eCPLedger_Payer_Key = LP.eCPLedger_Payer_Key
WHERE UPPER(LP.eCPLedger_Payer_ID) = 'SELF' and LM.eCPAccount_Key='0481843194'
应该做的工作!
我建议阅读加入 [ ^ ]。
这是一篇非常有趣的文章,显示了连接之间的差异: SQL连接的可视化表示 [ ^ ]
这篇关于SQL查询在同一列上使用In和Not In子句,我想以不同的方式重写下面的查询。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文