有人知道如何在Oracle中将行合并为一列吗?例如,假设我有这样一个表:
Customer Bought
----------------------------
John laptops
John Phones
Lisa Watches
我希望查询生成以下格式:
Customer CustomerBought
------------------------------------------
John Laptops, Phones
Lisa Watches
谢谢!
发布于 2016-08-11 18:51:19
with data_qry (name, item)
as
(select 'John', 'Laptop' from dual union all
select 'John', 'Phone' from dual union all
select 'Lisa', 'Watches' from dual union all
select 'Lisa', 'Glasses' from dual
)
select name, listagg(item, ', ') within group (order by item) as items
from data_qry
group by name
https://stackoverflow.com/questions/38903992
复制相似问题