sql查询一个表不包含另一个表的数据,两种方法。

1、用minus函数的方式:

select 

from 
CMN_FUND
where 
FUND_CODE_ in 
(select FUND_CODE_ from CMN_FUND minus select FUND_CODE_ from CMN_PROMOTION_FUND where FUND_CODE_ in 
(select FUND_CODE_ from CMN_PROMOTION_FUND where SELLPROMOTE_CODE_ = #{promotionCode}))
and 
FUNDCOMP_CODE_ = #{fundCompCode} 
order by 

FUND_CODE_



2、用not in来处理:

select 
f.FUND_CODE_, f.SHORT_NAME
from
CMN_FUND f, CMN_PROMOTION_FUND p
where
f.FUND_CODE_ = p.FUND_CODE_
and
f.FUND_CODE_ not in (SELECT FUND_CODE_ from CMN_PROMOTION_FUND where PROMOTION_CODE = #{promotionCode})
and 
f.FUNDCOMPCODE = #{fundCompCode}

猜你喜欢

转载自blog.csdn.net/weixin_41377877/article/details/80407855