取代in的方式-创建临时表进行多条的连表查询

        CREATE TEMPORARY TABLE IF NOT EXISTS username_temp select temp.dzh_customer_id from
        <foreach collection="list" index="index" item="item" open="(" separator="union" close=")">
            select dzh_customer_id from wk_crm_dzh_customer where username = #{item}
        foreach>
        temp;
        CREATE INDEX IX_username_temp ON username_temp(dzh_customer_id);
        select <include refid="Base_Column_List" />,cdc.id as dzh_customer_unique_id,
        cdc.username, cdc.dzh_customer_id, cdc.status, cdc.weights, cdc.create_time, cdc.update_time
        from wk_crm_customer cc
        inner join  wk_crm_dzh_customer cdc on cc.dzh_customer_id = cdc.dzh_customer_id
        inner join username_temp b on cdc.dzh_customer_id = b.dzh_customer_id
        order by cc.update_time asc;
        DROP TEMPORARY TABLE IF EXISTS username_temp;

你可能感兴趣的:(笔记,java,数据库,sql)