oracle行转列和列转行(pivot 和 unpivot 函数,wm_concat函数 )
create table demo(id int,name varchar(20),nums int); ---- 创建表
insert into demo values(1, '苹果', 1000);
insert into demo values(2, '苹果', 2000);
insert into demo values(3, '苹果', 4000);
insert into demo values(4, '橘子', 5000);
insert into demo values(5, '橘子', 3000);
insert into demo values(6, '葡萄', 3500);
insert into demo values(7, '芒果', 4200);
insert into demo values(8, '芒果', 5500);
---固定行转列
select * from
(select name,nums from demo) pivot (sum(nums) for name in ('苹果', '橘子', '葡萄', '芒果'));
---动态行转列
select * from (
select stat_time,target_code,sum(target_value) over(partition by stat_time order by target_code) as target_value from (
select stat_time,target_code,sum(target_value) as target_value from user_data_daily
where target_type='100001' and appkey='1400140930701' and stat_time>=date'2017-04-01' and stat_time<date'2017-06-01'
group by stat_time,target_code
) order by stat_time,target_code
)pivot xml (
sum(target_value) for target_code in (any)
);
oracle行转列和列转行(pivot 和 unpivot 函数,wm_concat函数 )的更多相关文章
- T-SQL行列相互转换命令:PIVOT和UNPIVOT使用详解
最近在维护一个ERP 做二次开发 ,在查找数据源的时候看到前辈写的SQL ,自己能力有限 ,就在网上找找有关这几个关键字的使用方法.做出随笔以做学习之用 T-SQL语句中,PIVOT命令可以实现数据表 ...
- Oracle11g 行列转换函数PIVOT and UNPIVOT
作为Oracle开发工程师,推荐大伙看看 PIVOT and UNPIVOT Operators in Oracle Database 11g Release 1 This article shows ...
- Oracle 行转列pivot 、列转行unpivot 的Sql语句总结
这个比较简单,用||或concat函数可以实现 select concat(id,username) str from app_user select id||username str from ap ...
- [转]Oracle SQL函数pivot、unpivot转置函数实现行转列、列转行
原文地址:http://blog.csdn.net/seandba/article/details/72730657 函数PIVOT.UNPIVOT转置函数实现行转列.列转行,效果如下图所示: 1.P ...
- Oracle行转列、列转行的Sql语句总结
多行转字符串 这个比较简单,用||或concat函数可以实现 SQL Code 12 select concat(id,username) str from app_userselect i ...
- Oracle行转列、列转行的Sql语句总结(转)
多行转字符串 这个比较简单,用||或concat函数可以实现 select concat(id,username) str from app_userselect id||username str f ...
- oracle行转列、列转行、连续日期数字实现方式及mybatis下实现方式
转载请注明出处:https://www.cnblogs.com/funnyzpc/p/9977591.html 九月份复习,十月份考试,十月底一直没法收心,赶在十一初 由于不可抗拒的原因又不得不重新找 ...
- 数据库行转列、列转行,pivot透视多列
这就是典型的行转列问题. 首先说下最简单的思路 用union all select year,sum(m1) m1,sum(m2) m2,sum(m3) m3,sum(m4) m4 from ( s ...
- oracle行转列,列转行
多行转字符串这个比较简单,用||或concat函数可以实现 SQL Code select concat(id,username) str from app_userselect id||userna ...
- Oracle行转列/列转行
1.oracle的pivot函数 原表 使用pivot函数: with temp as(select '四川省' nation ,'成都市' city,'第一' ranking from dual u ...
随机推荐
- core项目打包时发现有的项目的xml文件不会被打包进去,怎么办?
我打包后发现打包后的文件夹内,不存在xml文件,所以swagger加载失败:然后经过测试发现Core项目打包的时候是默认不包含Xml文件的,VS里面也没有办法设置. 解决方法:手动修改项目文件,找到你 ...
- vue-cli中eslint配置
在项目目录下找到.eslintrc.js文件,使用编辑器打开进行编辑.在rules下添加space-before-function-paren.space-before-blocks.及semi的配置 ...
- linux gcc安装
2004年4月20日最新版本的GCC编译器3.4.0发布了.目前,GCC可以用来编译C/C++.FORTRAN.java.OBJC.ADA等语言的程序,可根据需要选择安装支持的语言.GCC 3.4.0 ...
- QTabWidget标签实现双击关闭(转)
重载了QTabWidget(由于tabBar()是protected),这样就可以获取到标签了. 1 class Tab : public QTabWidget 2 { 3 Q_OBJECT 4 pu ...
- 关于jQuery的源码学习
注:该思维学习自另一个博客:https://blog.csdn.net/software0017/article/details/80317348 以下为我自己总结的jQuery结构:
- mysql打印用户权限的小技巧
mysql5.5 5.6 SHOW GRANTS FOR mysql> SELECT DISTINCT CONCAT('SHOW GRANTS FOR ''',user,'''@''',host ...
- springboot系列(四)springboot 配置
在springboot出现之前,spring项目会存在多个配置文件,如web.xml,配置spring的多个spring-xxx.xml,xxx代表配置spring的某一功能,如aplication- ...
- MacOS文本编辑无法打不开GB18030
不要直接双击打开 而是 打开sublime text或者其他文本编辑后,从软件里面的open选型打开
- centos6/7启动故障排错
centos6启动流程修复: 实验一:删除initramfs-2.6.32-754.el6.x86_64.img进行恢复 该文件很重要initramfs-2.6.32-754.el6.x86_64.i ...
- NORDIC BLE升级
NRF52832 SDK15.3.0 概述: 所谓DFU(Device Firmware Update),就是设备固件升级的意思,而OTA是DFU的一种类型,准确说,OTA的全称应该是OTA DFU, ...