select p.prov_id, p.pro_name, a.area_id, a.area_desc, to_number(p.ord2) pro_ord ,a.ord area_ord
from dmcode_pub.dmcode_province p
left join dmcode_pub.dmcode_area a
on p.prov_id = a.prov_id
where a.is_valid = '1'
and p.s_n_mark is not null
and a.area_id != '999'
<if test='hasNanBei == "1"'>
<include refid="unionNorth"/>
<include refid="unionSouth"/>
</if>
<include refid="unionWhole"/>
<include refid="unionNorth"/>
这个在MyBatis查询数据库的sql中经常会出现。直接引入已经定义好的sql语句,方便后期维护以及代码的间接
refid
是引用的sql的id名称,一定要唯一,unionNorth
在xml中已经定义了
<sql id="unionNorth">
union all
select '112' prov_id,
'北十省' pro_name,
a.area_id,
a.area_desc,
-2 pro_ord ,
a.ord area_ord
from dmcode_pub.dmcode_province p
left join dmcode_pub.dmcode_area a
on p.prov_id = a.prov_id
where a.is_valid = '1'
and p.s_n_mark = '10'
and a.area_id != '999'
</sql>