简体   繁体   English

使用LISTAGG获取值,但避免对内部联接中使用的表进行分组

[英]Fetching value using LISTAGG but avoid grouping of a table used in Inner join

Hi I have an Oracle query like 嗨,我有一个Oracle查询,如

select listagg(name,',') within group (order by name)
from table t1 
inner join table t2 on t1.id=t2.id
inner join table t3 on t1.value=t3.value

but later i needed to fetch 2 more columns from another table t4 so i joined t4 but when i join the listagg is giving repeated values separated with comma 但是后来我需要从另一个表t4中再获取2列,所以我加入了t4,但是当我加入listagg时,给出了用逗号分隔的重复值

select listagg(name,',') within group (order by name)
from table t1 
inner join table t2 on t1.id=t2.id
inner join table t3 on t1.value=t3.value
inner join table t4 on t1.id=t4.id

I want to fetch these new two columns without effecting the LISTAGG function. 我想获取这两个新列而不影响LISTAGG函数。

By adding the joins you are getting names repeated in the results. 通过添加联接,您将在结果中得到重复的名称。 Assuming your joins are correct, you could use DISTINCT to resolve this: 假设联接正确,则可以使用DISTINCT来解决此问题:

select listagg(name,',') within group (order by name)
from (select distinct name
      from table t1 
      inner join table t2 on t1.id=t2.id
      inner join table t3 on t1.value=t3.value
      inner join table t4 on t1.id=t4.id
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM