关联查询

<sql id="checkOrgJoins">
left join rf_check_org c on c.apply_id=a.id
</sql>

<sql id="column" >
a.id,
name,
id_card as idCard,
family_num as familyNum,
phone,
domicile_place as domicilePlace,
family_address as familyAddress,
hard_level as hardLevel,
separate_status as separateStatus,
is_village as isVillage,
house_status as houseStatus,
total_income as totalIncome,
fee_income as feeIncome,
manage_income as manageIncome,
transfer_income as transferIncome,
property_income as propertyIncome,
other_income as otherIncome,
medical_cost as medicalCost,
edu_cost as eduCost,
accident_cost as accidentCost,
other_cost as otherCost,
medical_cost_memo as medicalCostMemo,
edu_cost_memo as eduCostMemo,
accident_cost_memo as accidentCostMemo,
other_cost_memo as otherCostMemo,
hard_reason as hardReason,
other_hard_reason as otherHardReason,
need_hand as needHand,
other_need as otherNeed,
a.create_by as createBy,
a.create_date as createDate,
a.update_by as updateBy,
a.update_date as updateDate,
a.del_flag as delFlag,
a.org_id as orgId,
a.inspect_status as inspectStatus,
a.check_status as checkStatus,
a.sb_date as sbDate,
a.is_bank_inspect as isBankInspect,
a.is_police_inspect as isPoliceInspect,
a.is_realEstateinspect as isRealEstateinspect,
a.is_houseDept_inspect as isHouseDeptInspect,
a.is_insuranceDept_inspect as isInsuranceDeptInspect
</sql>

<select id="selectFamilyByOrgId" resultType="RfApplyFamily" >
select <include refid="column" />
from rf_apply_family a
<include refid="checkOrgJoins" />
where c.org_id=#{orgId}
</select>

<select id="selectFamilyByOrgIdAndName" resultType="RfApplyFamily" >
select <include refid="column" />
from rf_apply_family a
<include refid="checkOrgJoins" />
where c.org_id=#{orgId} and name=#{name}
</select>

原文地址:https://www.cnblogs.com/fxx5/p/10785276.html