Listagg() within group() 多行合并为一行函数

https://note.youdao.com/ynoteshare1/index.html?id=dbf6153529ceba0f5f9707758c237dfe&type=note#/
 

-- 1.查询部门为20的员工列表
SELECT t.DEPTNO,t.ENAME FROM SCOT

2.使用  listagg() WITHIN GROUP ()  将多行合并成一行
SELECT
	T .DEPTNO,
	listagg (T .ENAME, ',') WITHIN GROUP (ORDER BY T .ENAME) names
FROM
	SCOTT.EMP T
WHERE
	T .DEPTNO = '20'
GROUP BY
	T .DEPTNO

3. 使用 listagg() within GROUP () over  将多行记录在一行显示
SELECT
	T .DEPTNO,
	listagg (T .ENAME, ',') WITHIN GROUP (ORDER BY T .ENAME) over(PARTITION BY T .DEPTNO)
FROM
	SCOTT.EMP T
WHERE
	T .DEPTNO = '20' 

 

你可能感兴趣的:(问题积累)