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}


版权声明:本文为weixin_41377877原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。