欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

A表中的数据根据条件,不能再B表中存在,显示A表符合条件的数据

程序员文章站 2022-07-12 14:07:23
...

该代码来自某QQ
只能借鉴,类似需求可以使用

select c.*
from (
    select 
        p2p_funds_details.id_,
        p2p_funds_details.fund_id_,
        p2p_funds_details.cur_stage_no_,
        b.profit_plan_,
        b.period_length_,
        b.period_unit_
    from 
        p2p_funds_details ,
        p2p_plan_bids
    where 
        p2p_funds_details.plan_bid_id_ = p2p_plan_bids.id_
        and p2p_funds_details.insert_date = '2018-10-10'
        and p2p_funds_details.status_ in (0,2)
        and p2p_funds_details.cur_stage_no_


    ) c
    left join
    (
        select 
            p.fund_id as fid,
            max(p.cur_stage_no_) as cur_stage_no_2,
        from 
            p2p_funds_details p,
            p2p_plan_bids b
        where 
            p.plan_bid_id = b.id_
        group by p.fund_id_ 
    ) t on (c.fund_id = t.fid)
where c.cur_stage_no_ != t.cur_stage_no_2;