以下脚本为我提供了一个单行表格,显示了' manuf_skus'和' distr_skus'在一行中(使用' listagg'功能)......
select
pd.part_no,
pd.catnr,
pd.prodtyp,
pd.packtyp,
pd.description,
ip.purchase_type,
li.cust_catnr categroy,
li.licence_expire,
listagg (nrb.p_catnr, ', ') WITHIN GROUP (ORDER BY nrb.p_catnr) manuf_skus,
listagg (st.selection_no, ', ') WITHIN GROUP (ORDER BY st.selection_no) distr_skus,
nvl(pd.fod_idc, 'N') FOD_IDC,
(select max(acp.qty_free_idc)
from oes_fod_match acp
where pd.part_no = acp.part_no
and acp.type = 'SUP'
and acp.cre_dat = (select max(acp1.cre_dat)
from oes_fod_match acp1
where acp.part_no = acp1.part_no
and acp1.qty_free > 0
and acp1.type = 'SUP')) qty_free_idc,
(select nvl(sum(pl.qty_onhand), 0)
from part_loc pl
where pl.part_no = pd.part_no
and pl.location_type = 'IN') total_stock_comp,
(select nvl(max(pp.qty), 0)
from oes_purpos pp
where pp.av_part_no = pd.part_no
and pp.c_status != 'D'
and pp.datneu = (select max(pp1.datneu)
from oes_purpos pp1
where pp1.av_part_no = pp.av_part_no
and pp1.c_status != 'D')) last_aw_po_qty,
(select nvl(sum(ps.requ_qty - nvl(ps.del_qty, 0)), 0)
from oes_purpos pp,
oes_purseg ps
where ps.headnr = pp.headnr
and ps.posnr = pp.posnr
and pp.av_part_no = pd.part_no
and ps.c_status not in ('9', 'D')
and ps.o_status not in ('D', '9')) open_aw_po_qty,
(select sum(al.qty_required)
from allocations al
where pd.part_no = al.component_part
and al.status_code between '4' and '8') comp_alloc
FROM part_description pd
INNER JOIN inventory_purchase ip
ON ip.part_no = pd.part_no
INNER JOIN scm_prodtyp pt
ON pt.prodtyp = pd.prodtyp
INNER JOIN oes_fod_match acp
ON acp.part_no = pd.part_no
INNER JOIN leos_item li
ON pd.part_no = li.av_part_no
INNER JOIN inventory_purchase ip
ON ip.part_no = pd.part_no
INNER JOIN scm_prodtyp pt
ON pt.prodtyp = pd.prodtyp
INNER JOIN oes_fod_match acp
ON acp.part_no = pd.part_no
INNER JOIN part_description pd3
ON pd3.part_no = pd.part_no
INNER JOIN NCF_COMPPART ncf
ON ncf.item_part_no = pd.part_no
INNER JOIN oes_nrbom nrb
ON ncf.catnr = nrb.c_catnr
AND ncf.prodtyp = nrb.c_prodtyp
AND ncf.packtyp = nrb.c_packtyp
AND ncf.vernr = nrb.c_vernr
INNER JOIN part_description pd2
ON nrb.p_catnr = pd2.catnr
AND nrb.p_prodtyp = pd2.prodtyp
AND nrb.p_packtyp = pd2.packtyp
LEFT OUTER JOIN BDS_SELECTION_ORG@sid_to_cdsuk st
ON 9||nrb.p_catnr = st.selection_no
WHERE pd.cunr in ('649830', 'W30000')
and pd.catnr = '2EDVD0017'
and pd.fod_idc = 'Y'
and pt.prodgrp = 'AW'
GROUP BY
pd.part_no,
pd.catnr,
pd.prodtyp,
pd.packtyp,
pd.description,
ip.purchase_type,
li.cust_catnr,
li.licence_expire,
pd.fod_idc
我想添加的是以下子查询......
(select sum(ds.planqty - nvl(ds.delqty, 0))
from oes_opos op,
oes_oposdelseg ds
where ds.ordnr = op.ordnr
and ds.posnr = op.posnr
and op.catnr = nrb.p_catnr
and op.prodtyp = nrb.p_prodtyp
and op.packtyp = nrb.p_packtyp
and ds.c_status not in ('9', 'D')
and op.ol_typ = 'XX'
group by
pd.catnr, nrb.catnr, nrb.prodtyp, nrb.packtyp) open_manuf_qty
...为了完成这项工作,我必须添加以下GROUP BY'
nrb.p_catnr,
nrb.p_prodtyp,
nrb.p_packtyp
但是,当我添加这个子查询时,' manuf_skus'和' distr_skus'不再是一排。我认为这是因为我必须添加额外的组别。是否有添加此sum子查询并仍保留一行?
由于 所有
答案 0 :(得分:0)
其他行是否重复?如果是这样,您可以尝试添加不同的:
select distinct
pd.part_no,
pd.catnr,
pd.prodtyp,
...