oracle 小白有问,如何将查询结果相连接
Z_ORG_IDZ_CHECK_RESULTSUM(Z_DAY_VALUS)SUM(Z_WEEKS_VALUS)SUM(Z_MONTH_VALUS)
109238647FQ012
109238647HY5183142
109238647KT233
109238647LC359
109238648FQ0812
109238648HY0812
109238648KT009
109238648LC005

如题,根据org_id,将z_check_result,汇总显示为

Z_ORG_IDZ_CHECK_RESULTSUM(Z_DAY_VALUS)SUM(Z_WEEKS_VALUS)SUM(Z_MONTH_VALUS)
109238647FQ-HY-KT-LC0-51-2-31-83-3-52-142-3-9
109238648FQ-HY-KT-LC0-0-0-08-8-0-012-12-9-5

表1:

image.png

表2:

image.png

image.png

FRzengjie 发布于 2020-3-17 14:41 (编辑于 2020-3-17 15:33)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
0
axingLv6专家互助
发布于2020-3-17 14:48

可以按照这个,然后将分隔符替换成横杆-

分组合并字符串-https://help.finereport.com/doc-view-2349.html

最佳回答
0
dobeyluLv4见习互助
发布于2020-3-17 15:25(编辑于 2020-3-17 15:25)

用wm_concat,但是默认是用逗号拼接的,在处理一下就好了

  • FRzengjie FRzengjie(提问者) select a.z_org_id,a.Z_CHECK_RESULT,sum(z_day_valus),sum(z_weeks_valus),sum(z_month_valus) from (select a.z_org_id,b.Z_CHECK_RESULT,a.z_org_nm,count(a.id_key)z_day_valus,0 z_weeks_valus,0 z_month_valus from zlv_check_note_m a,zlv_check_note_l b where b.Z_CHECK_RESULT in(500074,500075,500076,500077,510076) and a.id_key=b.vou_id and b.Z_CHECK_DATE=\'2020-03-08\' group by a.z_org_id,b.Z_CHECK_RESULT,a.z_org_nm union all select a.z_org_id,b.Z_CHECK_RESULT,a.z_org_nm,0,count(a.id_key)z_weeks_valus,0 z_month_valus from zlv_check_note_m a,zlv_check_note_l b,ZLT_WEEKLY_DETAIL c where b.Z_CHECK_RESULT in(500074,500075,500076,500077,510076) and a.id_key=b.vou_id and b.z_weeks=c.z_weeks and c.z_DATE=\'2020-03-08\' group by a.z_org_id,b.Z_CHECK_RESULT,a.z_org_nm union all select a.z_org_id,b.Z_CHECK_RESULT,a.z_org_nm,0 z_day_valus,0 z_weeks_valus,count(a.id_key) z_month_valus from zlv_check_note_m a,zlv_check_note_l b where b.Z_CHECK_RESULT in(500074,500075,500076,500077,510076) and a.id_key=b.vou_id and substr(b.Z_check_DATE,0,7)=substr(\'2020-03-08\',0,7) group by a.z_org_id,b.Z_CHECK_RESULT,a.z_org_nm) a group by a.z_org_id,a.Z_CHECK_RESULT,a.z_org_nm
    2020-03-17 15:28 
  • FRzengjie FRzengjie(提问者) 我菜的恼火,试了几次,不行,麻烦大佬。 select a.z_org_id,dbms_lob.substr(wmsys.wm_concat(decode(a.Z_CHECK_RESULT,\'500074\',\'怀孕\',\'500075\',\'返情\',\'500076\',\'流产\',\'500077\',\'空胎\',\'510076\',\'隐流\'))) Z_CHECK_RESULT,dbms_lob.substr(wmsys.wm_concat(z_day_valus)),dbms_lob.substr(wmsys.wm_concat(z_weeks_valus)),dbms_lob.substr(wmsys.wm_concat(z_month_valus)) from (select a.z_org_id,b.Z_CHECK_RESULT,a.z_org_nm,count(a.id_key)z_day_valus,0 z_weeks_valus,0 z_month_valus from zlv_check_note_m a,zlv_check_note_l b where b.Z_CHECK_RESULT in(500074,500075,500076,500077,510076) and a.id_key=b.vou_id and b.Z_CHECK_DATE=\'2020-03-08\' group by a.z_org_id,b.Z_CHECK_RESULT,a.z_org_nm union all select a.z_org_id,b.Z_CHECK_RESULT,a.z_org_nm,0,count(a.id_key)z_weeks_valus,0 z_month_valus from zlv_check_note_m a,zlv_check_note_l b,ZLT_WEEKLY_DETAIL c where b.Z_CHECK_RESULT in(500074,500075,500076,500077,510076) and a.id_key=b.vou_id and b.z_weeks=c.z_weeks and c.z_DATE=\'2020-03-08\' group by a.z_org_id,b.Z_CHECK_RESULT,a.z_org_nm union all select a.z_org_id,b.Z_CHECK_RESULT,a.z_org_nm,0 z_day_valus,0 z_weeks_valus,count(a.id_key) z_month_valus from zlv_check_note_m a,zlv_check_note_l b where b.Z_CHECK_RESULT in(500074,500075,500076,500077,510076) and a.id_key=b.vou_id and substr(b.Z_check_DATE,0,7)=substr(\'2020-03-08\',0,7) group by a.z_org_id,b.Z_CHECK_RESULT,a.z_org_nm) a group by a.z_org_id--,a.Z_CHECK_RESULT,a.z_org_nm
    2020-03-17 15:28 
  • dobeylu dobeylu 回复 FRzengjie(提问者) 参考下这个吧 https://www.jianshu.com/p/1e847bb6c807
    2020-03-18 11:05 
  • 3关注人数
  • 468浏览人数
  • 最后回答于:2020-3-17 15:33
    请选择关闭问题的原因
    确定 取消
    返回顶部