mysql sum为空时默认显示0

 

<select id="selectCountData" resultType="java.util.Map" parameterType="RcdataEnclosedCommunity">

        select d.dept_id, d.dept_name,
               (select COALESCE(sum(a.building_num),0) from rcdata_enclosed_community a where a.del_flag='0' and a.dept_id=d.dept_id  and a.status='1') loudongcount,
               (select COALESCE(sum(a.unit_num),0) from rcdata_enclosed_community a where a.del_flag='0' and a.dept_id=d.dept_id  and a.status='1') danyuancount,
               (select COALESCE(sum(a.house_num),0) from rcdata_enclosed_community a where a.del_flag='0' and a.dept_id=d.dept_id  and a.status='1') hushucount,
               (select COALESCE(sum(a.person_num),0) from rcdata_enclosed_community a where a.del_flag='0' and a.dept_id=d.dept_id  and a.status='1') renkoucount
        from sys_dept d where d.type=3 and d.del_flag='0'

</select>

 

 

 

posted @ 2022-11-14 11:13  aaa111js  阅读(1537)  评论(0)    收藏  举报