wm_concat 行转列
select deptno 部门号,wm_concat(ename) 部门中员工的姓名 from emp group by deptno;
wm_concat(ename) 将部门中员工的姓名用,拼接
col 部门中员工的姓名 for a60
把列宽设置为60的宽度
************************************************************
SQL> select deptno,wm_concat(ename) from emp group by deptno;
DEPTNO
----------
WM_CONCAT(ENAME)
--------------------------------------------------------------------------------
10
CLARK,MILLER,KING
20
SMITH,FORD,ADAMS,SCOTT,JONES
30
ALLEN,JAMES,TURNER,BLAKE,MARTIN,WARD
SQL> set linesize 200;
SQL> col 部门中员工的姓名 for a60
SQL> select deptno 部门号,wm_concat(ename) 部门中员工姓名 from emp group by deptno;
部门号
----------
部门中员工姓名
---------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------
10
CLARK,MILLER,KING
20
SMITH,FORD,ADAMS,SCOTT,JONES
30
ALLEN,JAMES,TURNER,BLAKE,MARTIN,WARD
SQL> select deptno 部门号,wm_concat(ename) 部门中员工的姓名 from emp group by deptno;
部门号 部门中员工的姓名
---------- ------------------------------------------------------------
10 CLARK,MILLER,KING
20 SMITH,FORD,ADAMS,SCOTT,JONES
30 ALLEN,JAMES,TURNER,BLAKE,MARTIN,WARD
select deptno 部门号,wm_concat(ename) 部门中员工的名字--wm_concat行列转置 from emp group by deptno;
5.
wm_concat行转列
select deptno 部门号,wm_concat(ename) 部门中员工的姓名 from emp group by deptno;
使用分组函数2
WM_CONCAT 行转列
select deptno,wm_concat(ename) from emp group by deptno;
存疑,后续继续看下
set linesize 200
col 部门中员工的姓名 for a60
select deptno 部门号,wm_concat(ename) 部门中员工的别名 from emp group by deptno;
wm_concat 行转列
select deptno,wm_concat(ename) from emp group by deptno;
设置显示格式,在文本文档里面修改命令并保存,编辑器命令就会发生相应的变化,接下来是修改行款列宽:
SQL> set linesize 200
SQL> col 部门中员工的姓名 for a60
wm_concat(列名)行转列
select deptno 部门号,wm_concat(ename) 部门中员工的姓名 from emp group by deptno;
按照部门号分组,将相同部门号的员工以逗号分隔的形式展示到一行中
select count(distinct column_name) from table_name;不同数据求和