mybatis联接查询例子

where判断如果放在最外层就是对连接查询后的结果经行筛选。

SELECT * from (
        SELECT * from lw_area where lw_area.area_level <=3 and lw_area.area_id like '35%'
        ) la LEFT JOIN (
        select * from t_cas_area_statistics t
        where 1=1
        <if test="statist_date != null and statist_date != ''">
            and t.statist_date = #{statist_date}
        </if>
        <if test="resource_type!=null and resource_type != ''">
            and t.resource_type = #{resource_type}
        </if>
        ) t
        on la.area_id = t.area_code

 

posted @ 2019-01-03 15:06  护花使者  Views(166)  Comments(0Edit  收藏  举报