oracle中wm_concat()函数

select z.admission_code,z.print_date,z.delivery_code,z.supplier_code,z.supplier_text,
max(z.pxh),max(z.platform_action_text),max(z.confirm_point_text)
from 
(
select t.admission_code,t.print_date,t.delivery_code,t.supplier_code,t.supplier_text,
to_char(WM_CONCAT(to_char(t.PXH)) over (partition by t.admission_code  order by t.pxh))  pxh,
to_char(WM_CONCAT(to_char(t.platform_action_text)) over (order by t.pxh) )  platform_action_text,
to_char(WM_CONCAT(to_char(t.confirm_point_text)) over (order by t.pxh)) confirm_point_text
from 
 (
select a.PXH,m.admission_code,sysdate print_date,m.delivery_code,m.supplier_code,
b.platform_action_text,c.confirm_point_text,d.supplier_text
FROM wm_platform_delivery m 
left join  wm_platform_confirm_info a  on m.admission_code=a.admission_code
left join  WM_PLATFORM_ACTION b on  a.warehouse_code=b.warehouse_code and a.platform_action=b.platform_action    
left join  WM_PLATFORM_CONFIRMATION c on  a.warehouse_code=c.warehouse_code and a.confirm_point=c.confirm_point
left join  wm_supplier d on m.supplier_code=d.supplier_code
WHERE m.ADMISSION_CODE=631  
  ) t
 --上面用了partition by,这里就可以省略 group by t.admission_code,t.print_date,t.delivery_code,t.supplier_code,t.supplier_text
) z
 group by z.admission_code,z.print_date,z.delivery_code,z.supplier_code,z.supplier_text

sql解析:

to_char(WM_CONCAT(to_char(t.PXH)) over (partition by t.admission_code  order by t.pxh))  pxh,
to_char(WM_CONCAT(to_char(t.platform_action_text)) over (order by t.pxh) )  platform_action_text,
to_char(WM_CONCAT(to_char(t.confirm_point_text)) over (order by t.pxh)) confirm_point_text
to_char():加了to_char(),是为了预防字符集原因,合并后的列查出来空的问题

partition by :分组的意思, 等同于group by ,加了这个就可以省略group by

over(): 如果合并后需要排序,就需要加这个反之不需要

原始数据

最终数据(合并并排序)



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值