Oracle行转列、数据合并、递归用法
一、Oracle--case when 行转列
case when 语法结构
case 列名
when 条件值1 then 选项1
when 条件值2 then 选项2
.......
else 默认值 end
案例
-- Oracle 行列转换
-- 数据,使用scott用户的emp表数据
select * from scott.emp t where rownum<=50;
-- 表字段说明:
-- empno, ename, job, mgr, hiredate, sal, comm, deptno
-- 员工编号,员工姓名,岗位,领导编号,入职日期,薪资,奖金,部门编号
-- 需求:查询scott.emp表中,每个部门的人数,并进行行转列显示
select
max(case when deptno=10
then total else 0 end) "10",
ma