Oracle SQL - 将多行放入一个字段中

时间:2018-01-11 20:57:15

标签: sql oracle oracle11g

我有一张这样的表:

enter image description here

我需要一个显示此输出的查询(无PL / SQL):

enter image description here

因此,对于每个产品ID ,我希望投放类型字段中的投放类型的不同值。

有没有办法通过Oracle中的“简单”查询获得此结果?

我正在使用Oracle 11g。

提前致谢!

1 个答案:

答案 0 :(得分:3)

在获取每个产品ID的不同投放类型后使用listagg。 (请注意,聚合字符串有4000个字符的限制。)

select product_id,listagg(delivery_type,'/') within group (order by delivery_type)
from (select distinct product_id,delivery_type from tbl) t
group by product_id
相关问题