我有以下查询来生成某些产品的 ID 和分数
Select
tm.product_id,
listagg(tm.book_id || '(' || tm.score || ')',',')
within group (order by tm.product_id) as matches
from
tl_product_match tm
where
tm.book_id is not null
group by
tm.product_id
union
Select
stm.product_id,
listagg(stm.video_id || '(' || stm.score || ')',',')
within group (order by stm.product_id) as matches
from
tl_product_match stm
where
stm.video_id is not null
group by
stm.product_id
查询产生如下所示的输出:
productId | matches
---------------------------------------------
1 | 123(30), 76565, 7687(500), 243(5)
2 | 352(30), 9(5), 34234(500), 43(5)
2 | 25(30), 78, 324(500), 23434(5)
3 | 546(30), 768, 34234(500), 324(5)
两个问题:
- 是否可以修改查询以删除联合并仍然产生相同的结果?
ProductId 2 重复了两次(即每个工会各有一行),我该怎么做才能在同一行中显示 productId 2?IE
productId | matches ----------------------------------------------------------------------------- 1 | 123(30), 76565, 7687(500), 243(5) 2 | 352(30), 9(5), 34234(500), 43(5), 25(30), 78, 324(500), 23434(5) 3 | 546(30), 768, 34234(500), 324(5)
提前致谢。