left join 一对多时, 把需要的子表数据 拼到主表,一行显示

--1.wm_concat(r.recipe_no), 在oracle  12c中不支持
--2.listagg(fxwt,',') within GROUP (order by fxwt) as fxwt , 数据过长不支持
--3.xmlagg(xmlparse(content fxwt||',' wellformed) order by fxwt).getclobval() as fxwt

select id,小明,wm_concat(子表.做什么的字段) from 主表
    lfet join 子表 on  关系=关系

 

SELECT 
    q.question_no,
  listagg(r.recipe_no, ',') within group(ORDER BY r.register_flow) AS recipe_no,
  listagg(r.pay_status, ',') within group(ORDER BY r.register_flow) AS pay_status
  --xmlagg(xmlparse(content r.recipe_no||',' wellformed) order by r.register_flow).getclobval() as recipe_no
FROM
  out_question q 
left join 
  (select r.register_flow, r.recipe_no,concat(concat(r.recipe_no,','),r.pay_status_id) as pay_status from out_recipe r ) r
on q.register_flow=r.register_flow
where q.register_flow='3ee0bba1424a44158a96114eff838ba7'
group by q.question_no

left join 一对多时, 把需要的子表数据 拼到主表,一行显示_第1张图片

你可能感兴趣的:(oracle)