select a.room_id id,
a.room_name,
sum(case
when a.bed_state = 0 then
1
else
0
end) emptyBeds,
sum(case
when a.bed_state = 1 then
1
else
0
end) usedBeds,
LISTAGG(TO_CHAR(b.DEPT_NAME), ', ') WITHIN GROUP(ORDER BY b.DEPT_NAME) AS DEPT_NAME,
a.floor_id from V_PRESORT_BEDS a left join v_dorm_studentbed b on a.id = b.BED_ID where a.bed_state = 0 or a.BED_STATE = 1 and (a.building_id = 1750321066962288641 OR a.unit_id = 1750321066962288641)
AND a.room_sex = '1'
group by a.room_id, a.room_name, a.floor_id order by a.room_name, length(a.room_name)
本来是用 listagg 函数把院系转化成一行,
LISTAGG(TO_CHAR(b.DEPT_NAME), ', ') WITHIN GROUP(ORDER BY b.DEPT_NAME) AS DEPT_NAME,
发现结果乱码如下:
多次尝试后发现 加上to_char() 就好了。。。
LISTAGG(TO_CHAR( b.DEPT_NAME), ', ') WITHIN GROUP (ORDER BY b.DEPT_NAME) AS DEPT_NAME,