在 oracle优化培训之第二期 的课程中, 我给学员讲了with as的几个用途,下面逐一介绍:
1. 通过materilize生成临时表, 达到优化SQL目的...., 下面示例是在19c之前, 使用listagg并去重的一种写法, with as的作用是生成了几行测试记录, 避免了建表和插入记录的麻烦:
with test_data(col1,col2,created_by...union all select 2, 6, 'Ram' from dual
union all select 2, 7, 'Jack' from dual
)
SELECT col1 ,
listagg...(col2 , ',') within group (order by col2 ASC) AS orig_value,
listagg(CASE WHEN rn=1 THEN col2 END..., ',') within group (order by col2 ASC) AS distinct_value
from
(
select a.