listagg wm_concat 行转列
一、
这个写法和wm_concat相似,
listagg(day,',')要把哪一列转换为同一行
within group (order by day)同一行如何排序
with temp as
(
select '1月' month, '' day from dual union all
select '2月' month, '' day from dual union all
select '2月' month, '' day from dual union all
select '3月' month, '' day from dual union all
select '3月' month, '' day from dual union all
select '3月' month, '' day from dual
)
select
month,listagg(day,',')within group (order by day ) days
from temp
group by month;

with temp as
(
select '1月' month, '' day from dual union all
select '2月' month, '' day from dual union all
select '2月' month, '' day from dual union all
select '3月' month, '' day from dual union all
select '3月' month, '' day from dual union all
select '3月' month, '' day from dual
)
select
month,
to_char(wm_concat(day))
from temp
group by month;

二、
不使用group by
with temp as
(
select '1月' month, '' day from dual union all
select '2月' month, '' day from dual union all
select '2月' month, '' day from dual union all
select '3月' month, '' day from dual union all
select '3月' month, '' day from dual union all
select '3月' month, '' day from dual
)
select month ,
listagg(day,',')within group (order by day) over (partition by month) DAYS
from temp

with temp as
(
select '1月' month, '' day from dual union all
select '2月' month, '' day from dual union all
select '2月' month, '' day from dual union all
select '3月' month, '' day from dual union all
select '3月' month, '' day from dual union all
select '3月' month, '' day from dual
)
select *
from (select month,
to_char(wm_concat(day) over(partition by month order by day)) days,
row_number() over(partition by month order by day desc) rn
from temp)
where rn = 1

listagg wm_concat 行转列的更多相关文章
- Oracle之多行记录变一行记录,行变列,并排序(wmsys.wm_concat)
原帖:http://www.cnblogs.com/nayitian/p/3231734.html wmsys.wm_concat Definition: The Oracle PL/SQL WM_C ...
- oracle行转列函数WMSYS.WM_CONCAT 用法
1.通过 10g 所提供的 WMSYS.WM_CONCAT 函数即可以完成 行转列的效果 select group_code, wm_concat(display_title) from DR_OPM ...
- Oracle行转列LISTAGG函数
工作过程中需要将查询的数据分组并显示在一行.以往的工作经验,在sql server中可以用for xml path来实现. 现提供Oracle数据库的行转列方式 oracle11g官方文档简介如下: ...
- oracle行转列和列转行(pivot 和 unpivot 函数,wm_concat函数 )
create table demo(id int,name varchar(20),nums int); ---- 创建表insert into demo values(1, '苹果', 1000); ...
- Oracle行转列、列转行的Sql语句总结
多行转字符串 这个比较简单,用||或concat函数可以实现 SQL Code 12 select concat(id,username) str from app_userselect i ...
- oracle行转列(连接字符串函数)
方法一:wmsys.wm_concat(column) 介绍:其函数在Oracle 10g推出,在10g版本中,返回字符串类型,在11g版本中返回clob类型.括号里面的参数是列,而且可以是多个列的集 ...
- ORACLE行转列(行转1列,行转多列)
在oracle 11g release 2 版本中新增的listagg函数,listagg是一个实现字符串聚合的oracle内建函数;listagg(column,'分隔符') within grou ...
- Oracle 行转列pivot 、列转行unpivot 的Sql语句总结
这个比较简单,用||或concat函数可以实现 select concat(id,username) str from app_user select id||username str from ap ...
- 数据库行转列、列转行,pivot透视多列
这就是典型的行转列问题. 首先说下最简单的思路 用union all select year,sum(m1) m1,sum(m2) m2,sum(m3) m3,sum(m4) m4 from ( s ...
随机推荐
- docker故障问题修复
systemctl start docker启动 systemctl restart docker重启 执行 vi /etc/sysconfig/selinux , 把 selinux 属性值改为di ...
- jquery 增加与删除数组元素
1.数组元素的添加 demoArray.push(value); var demo=new Array(); var key=[4,5]; demo.push(1);//插入数字 demo.push( ...
- Python中级 —— 07标准库
标准库学习 1. The Python Standard Library[https://docs.python.org/3.5/library/] ( 3.5.5 Documentation ) 1 ...
- 大数据学习--day14(String--StringBuffer--StringBuilder 源码分析、性能比较)
String--StringBuffer--StringBuilder 源码分析.性能比较 站在优秀博客的肩上看问题:https://www.cnblogs.com/dolphin0520/p/377 ...
- ruby on rails 环境搭建(mac or ubuntu)
环境配置前操作 mac: app_store安装x-code ubuntu: 终端->配置文件->首选项->命令->以shell方式登录 安装RVM mac: $ ruby - ...
- Dbshop v1.3任意用户密码重置漏洞
0x00 前言 年也过的差不多了,各自也都回到岗位忙碌起来了,新的一年祝大家诸事顺利,洞洞高危!好了进入正题 0x01 漏洞简介 本次主要写个简单的逻辑漏洞!然后抛个Message 内置高危. 1.找 ...
- 最短寻道优先算法(SSTF)——磁盘调度管理
原创 最近操作系统实习,敲了实现最短寻道优先(SSTF)——磁盘调度管理的代码. 题目阐述如下: 设计五:磁盘调度管理 设计目的: 加深对请求磁盘调度管理实现原理的理解,掌握磁盘调度算法. 设计内容: ...
- (数据科学学习手札50)基于Python的网络数据采集-selenium篇(上)
一.简介 接着几个月之前的(数据科学学习手札31)基于Python的网络数据采集(初级篇),在那篇文章中,我们介绍了关于网络爬虫的基础知识(基本的请求库,基本的解析库,CSS,正则表达式等),在那篇文 ...
- SVG中嵌入HTML元素
<?xml version="1.0" standalone="yes"?> <style> .clsfont{ border:1px ...
- 20155236 《Java程序设计》实验一(Java开发环境的熟悉)实验报告
20155236 <Java程序设计>实验一(Java开发环境的熟悉)实验报告 一.实验内容及步骤 (一)使用JDK编译.运行简单的java程序 命令行下的程序开发 因为我用的是windo ...