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(): 如果合并后需要排序,就需要加这个反之不需要
原始数据
最终数据(合并并排序)