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 ...
随机推荐
- DotNet跨平台 - docker部署.net core2.0项目
参考文档: https://docs.docker.com/install/linux/docker-ce/centos/ http://www.dockerinfo.net/document htt ...
- dotnetcore下解压zip文件,解决中文文件名乱码问题
(迄今为止网上那些说的用Encoding.Default解决中文文件名乱码的都不能真正解决问题!) 1.在程序开始处 Encoding.RegisterProvider(CodePagesEncodi ...
- 普通选项卡+自动播放功能+向前/向后按钮 原生js
今天做了幻灯片,主要功能包括:普通选项卡,向前/向后播放按钮,向前?向后播放功能,自动播放功能 要实现简单选项卡功能是没有问题的,但是添加功能就出现各种各样的问题了 遇到的问题:1 下标问题 2普通选 ...
- jmeter分布式压力测试配置操作
前提准备条件:1.主控机一台为master,ip地址:10.8.88.1772.负载机一台为slave, ip地址:10.8.88.1193.主控机和负载机都安装一样的JDK环境和jmeter版本.5 ...
- golang使用ssh远程连接服务器并执行命令
安装golang.org/x 直接去github上面,把https://github.com/zieckey/golang.org,把整个目录拷贝下来放到你的gopath下面即可.记住在gopath的 ...
- FreeRTOS编程风格
数据类型 基本使用的是标准C里面的数据类型,但是针对不同的处理器,对标准C的数据类型又进行了重定义: 在FreeRTOS中详细的数据类型重定义在portmacro.h这个文件中,具体如下: /* Ty ...
- Mha-Atlas-MySQL高可用方案实践
一,mysql-mha环境准备 1.1 实验环境: 1.1 实验环境: 主机名 IP地址(NAT) 描述 mysql-master eth0:10.1.1.154 系统:CentOS6.5(6.x都可 ...
- django已经安装但是还是提示ModuleNotFoundError: No module named 'django'
首先查看自己django版本与python版本是否一致: 如果一致.可能是django安装的位置与python导包的位置不一致. 我将之前的python2.6升级到python3.6,结果pip in ...
- ComboGrid二级联动以及给二级联动赋默认值
<input name="buyStatus" id="upbuyStatus" style="width: 100%;height: 85%& ...
- easyUI-filebox图片上传和预览
转载自:https://blog.csdn.net/nvxiaq/article/details/77740516 备注: 1.如需上传多个图片可定义多个change_photo函数 在onChang ...