对于所有结果,good_name列为null。查询中出现什么问题?
select fp.id,
listagg(fpg.name, ',') within group(order by fpg.name) good_name
from fp_place_goods fppg join
fp_places fp on fppg.place_id = fp.id join
fp_goods fpg on fppg.good_id = fpg.id
GROUP BY fp.id
however query below works
select fp.id,
listagg(fpg.id, ',') within group(order by fpg.id) good_ids
from fp_place_goods fppg join
fp_places fp on fppg.place_id = fp.id join
fp_goods fpg on fppg.good_id = fpg.id
GROUP BY fp.id
select fp.id, fpg.name from fp_places fp join
fp_place_goods fppg on fp.id = fppg.place_id join
fp_goods fpg on fpg.id = fppg.good_id
返回图像中的结果
答案 0 :(得分:10)
之所以发生这种情况,是因为good_name是nvarchar,而to_char(fpg.name)解决了它。