Oracle-唯一的Listagg值 [英] Oracle - unique Listagg values
本文介绍了Oracle-唯一的Listagg值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是使用Listagg的新手.以下脚本在此方面起作用,它为我提供了一个值列表,但该列表重复了这些值.
I am new to using Listagg. The following script works in respect of it gives me a list of values but, the list duplicates the values.
是否可以使用Listagg仅返回唯一的值列表.
Is it possible to use Listagg to return only a unique list of values.
我正在使用oracle 10g.
I am using oracle 10g.
select distinct ds.catnr,ds.planqty, ds.ordnr, ds.posnr, ds.segnr,
listagg(case when not li.paco is null then (select unique max(li1.paco) from leos_item li1 where li.av_part_no = li1.av_part_no) end, ', ') within group (order by pd.part_no) inq_no
from oes_delsegview ds, oes_address ad, oes_opos op, oes_nrbom nr, scm_prodtyp sp, leos_item li, part_description pd
where ds.delnr = ad.key
and ad.adr = ds.deladr
and ds.pos_o_status not in ('9', 'D')
and ds.pos_c_status not in ('9', 'D')
and ds.seg_o_status not in ('9', 'D')
and ds.seg_c_status not in ('9', 'D')
and ds.cunr in ('W31170','W31172')
and ds.pos_type != 'RC'
and ds.ordnr = op.ordnr
and ds.posnr = op.posnr
and ds.catnr = pd.catnr
and ds.prodtyp = pd.prodtyp
and ds.packtyp = pd.packtyp
and ds.catnr = nr.p_catnr (+)
and ds.prodtyp = nr.p_prodtyp (+)
and ds.packtyp = nr.p_packtyp (+)
and nr.c_prodtyp = sp.prodtyp (+)
and sp.prodgrp (+) = 'COMP'
and substr(nr.c_prodtyp,1,2) not in ('MT','LF')
and nr.c_catnr = li.catnr (+)
and nr.c_prodtyp = li.prodtyp (+)
and nr.c_packtyp = li.packtyp (+)
and pd.catnr = '9780007938797'
group by ds.catnr,ds.planqty, ds.ordnr, ds.posnr, ds.segnr
我的Listagg的结果是:
The result of my Listagg is:
14/061127-12, 14/061127-16, 14/061127-16, 14/061127-16, 14/061127-16, 14/061127-16, 14/061127-16, 14/061127-16, 14/061127-16, 14/061127-16, 14/061127-16, 14/061127-16, 14/061127-16, 14/061127-16, 14/061127-16, 14/061127-16, 14/061127-16, 14/061127-16, 14/061127-16, 14/061127-16, 14/061127-16
我想看的是:
14/061127-12, 14/061127-16
任何帮助将不胜感激.
推荐答案
我删除了第一个distinct
,因为您已经group by
查询中的所有字段已经group by
,并用select
替换了case when
查询:
I removed the first distinct
since your already group by
all fields in your Select
query, and replaced the case when
with a select
query:
select ds.catnr,ds.planqty, ds.ordnr, ds.posnr, ds.segnr,
listagg((select distinct max(li1.paco) from leos_item li1 where li.av_part_no = li1.av_part_no and li.paco is not null), ', ') within group (order by pd.part_no) inq_no
from oes_delsegview ds, oes_address ad, oes_opos op, oes_nrbom nr, scm_prodtyp sp, leos_item li, part_description pd
where ds.delnr = ad.key
and ad.adr = ds.deladr
and ds.pos_o_status not in ('9', 'D')
and ds.pos_c_status not in ('9', 'D')
and ds.seg_o_status not in ('9', 'D')
and ds.seg_c_status not in ('9', 'D')
and ds.cunr in ('W31170','W31172')
and ds.pos_type != 'RC'
and ds.ordnr = op.ordnr
and ds.posnr = op.posnr
and ds.catnr = pd.catnr
and ds.prodtyp = pd.prodtyp
and ds.packtyp = pd.packtyp
and ds.catnr = nr.p_catnr (+)
and ds.prodtyp = nr.p_prodtyp (+)
and ds.packtyp = nr.p_packtyp (+)
and nr.c_prodtyp = sp.prodtyp (+)
and sp.prodgrp (+) = 'COMP'
and substr(nr.c_prodtyp,1,2) not in ('MT','LF')
and nr.c_catnr = li.catnr (+)
and nr.c_prodtyp = li.prodtyp (+)
and nr.c_packtyp = li.packtyp (+)
and pd.catnr = '9780007938797'
group by ds.catnr,ds.planqty, ds.ordnr, ds.posnr, ds.segnr
这篇关于Oracle-唯一的Listagg值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文