SELECT a.BUILD_BED_ID, CONCAT(b.DISTRICT_PROVINCIAL, b.DISTRICT_CITY) AS province_city, b.REAL_NAME,
b.CERTI_CODE, b.TEL, TRUNC(months_between(sysdate, b.BIRTHDAY)/12) AS age,
DECODE(b.GENDER, 'M','男','F', '女') gender, a.ADRESS_DETAIL as address,
a.NURSING_DEMAND_LEVEL, a.SRV_MODE, a.CHANGHU_NO, a.SPECIAL_ZONE, a.BED_NUMBER, TO_CHAR(a.BUILD_BED_TIME, 'yyyy-MM-dd') AS build_bed_time,
TO_CHAR((CASE a.STATUS WHEN 1 THEN (SELECT REMOVE_BED_TIME FROM CH_SRV_REMOVE_BED c WHERE c.BUILD_BED_ID=a.BUILD_BED_ID) ELSE NULL END), 'yyyy-MM-dd') AS remove_bed_time,
(CASE a.STATUS when 0 THEN '已建床' when 1 then '已撤床' end) AS status
FROM CH_SRV_BUILD_BED a, CH_DISABLE_INFO b where a.DISAB_INFO_ID = b.DISAB_INFO_ID
AND a.SRV_ORGAN_ID =#{req.srvOrganId}
<iftest="req.realName != null and req.realName != ''">
AND upper(a.REAL_NAME) LIKE '%' || upper#{req.realName}) || '%'
</if>
<iftest="req.certiCode != null and req.certiCode != ''">
AND upper(a.CERTI_CODE) = upper(#{req.certiCode})
</if>
<iftest="req.status != null and req.status != '' ">