【SQL】临时表解决小表跨库JOIN

-- SQL实现
select 10.00 as amount,'X031' as store_code 
union 
select 20.00 as amount,'D033' as store_code



-- MyBatis实现
select
        sd.daily_init_target_money  / tmp.reality_money as targetImplRate,
        tmp.reality_money  as salesAmount,
        sd.store_code
        from store_daily_sales_analyze sd
        join (
                <foreach collection="storeTargetDtoListList" item="storeTargetDtoListItem" 	  	index="index" separator="union">
                    select 
                    #{storeTargetDtoListItem.storeCode} as store_code,
                    #{storeTargetDtoListItem.salesAmount} as reality_money
                </foreach>
        )tmp on tmp.store_code = sd.store_code
        <where>
            <include refid="query_whereConditions"/>
        </where>
 
发布了22 篇原创文章 · 获赞 11 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/t1g2q3/article/details/103928311