目录:
1、case when----列转行 及其他用法
- case when 判断 then 值 else 值 end as 新字段名
- sum(case when 判断 then 值 else 值 end) as 新字段名
- case when 判断=A then 0
判断=B then 1 判断=C then 2 end as 新字段名
2、decode---列转行及其他用法
- decode(字段,值,如果是赋予值,如果否赋予值)
- sum(decode())
- decode(字段,值1,返回值1,值2,返回值2,值3,返回值3.....)
3、分组列转行,且合并组对应的值----vm_concat() 函数
4、unpivot-------多列合并转一列
5、使用union -------多列合并转一列
------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------
1、case when----列转行
比如依据scott用户下的emp表格,将job字段列转化成行。
原表
表转换
2、decode的普通用法、聚合函数用法
普通:使用emp表格,进行转换
decode的聚合:
如将下图的表,将每个客户的合同行转列,且求合同费用值。
decode(字段,判断值1,赋值1,判断值2,赋值2,判断值3,赋值3.....)
3、分组列转行,且合并组对应的值----vm_concat() 函数
4、unpivot-------多列合并转一列
5、使用union -------多列合并转一列