一、

这个写法和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 行转列的更多相关文章

  1. Oracle之多行记录变一行记录,行变列,并排序(wmsys.wm_concat)

    原帖:http://www.cnblogs.com/nayitian/p/3231734.html wmsys.wm_concat Definition: The Oracle PL/SQL WM_C ...

  2. oracle行转列函数WMSYS.WM_CONCAT 用法

    1.通过 10g 所提供的 WMSYS.WM_CONCAT 函数即可以完成 行转列的效果 select group_code, wm_concat(display_title) from DR_OPM ...

  3. Oracle行转列LISTAGG函数

    工作过程中需要将查询的数据分组并显示在一行.以往的工作经验,在sql server中可以用for xml path来实现. 现提供Oracle数据库的行转列方式 oracle11g官方文档简介如下: ...

  4. oracle行转列和列转行(pivot 和 unpivot 函数,wm_concat函数 )

    create table demo(id int,name varchar(20),nums int); ---- 创建表insert into demo values(1, '苹果', 1000); ...

  5. Oracle行转列、列转行的Sql语句总结

    多行转字符串 这个比较简单,用||或concat函数可以实现  SQL Code  12    select concat(id,username) str from app_userselect i ...

  6. oracle行转列(连接字符串函数)

    方法一:wmsys.wm_concat(column) 介绍:其函数在Oracle 10g推出,在10g版本中,返回字符串类型,在11g版本中返回clob类型.括号里面的参数是列,而且可以是多个列的集 ...

  7. ORACLE行转列(行转1列,行转多列)

    在oracle 11g release 2 版本中新增的listagg函数,listagg是一个实现字符串聚合的oracle内建函数;listagg(column,'分隔符') within grou ...

  8. Oracle 行转列pivot 、列转行unpivot 的Sql语句总结

    这个比较简单,用||或concat函数可以实现 select concat(id,username) str from app_user select id||username str from ap ...

  9. 数据库行转列、列转行,pivot透视多列

    这就是典型的行转列问题. 首先说下最简单的思路  用union all select year,sum(m1) m1,sum(m2) m2,sum(m3) m3,sum(m4) m4 from ( s ...

随机推荐

  1. 如何创建一个新的vue项目

    一.cnpm安装 1.百度node官网,进入官网下载安装包安装好node环境 2.成功后打开cmd命令行工具,执行node-v命令,查看node版本号,如果能输出版本号说明安装成功 3.推荐使用淘宝 ...

  2. [译文]程序员能力矩阵 Programmer Competency Matrix

    注意:每个层次的知识都是渐增的,位于层次n,也蕴涵了你需了解所有低于层次n的知识. 计算机科学 Computer Science   2n (Level 0) n2 (Level 1) n (Leve ...

  3. 使用CURL实现GET和POST方式请求

    /** 使用curl方式实现get或post请求@param $url 请求的url地址@param $data 发送的post数据 如果为空则为get方式请求return 请求后获取到的数据 */f ...

  4. T+API HTTPServer服务端

    该服务端是一个HTTP服务器,这样其他语言调用也方便. 出于某些原因,只支持Post方法,不打算支持其他方法,例如Get. API所接受的参数将以Json传送,回传的数据也是一个Json数据,一切只是 ...

  5. goland实现函数式链式编程

    先来看一段代码 package main import ( "fmt" elastic "gopkg.in/olivere/elastic.v2" ) type ...

  6. 类似register uint32_t __regPriMask __ASM("primask");的代码分析

    代码: #define __ASM __asm /*!< asm keyword for ARM Compiler */ #define __INLINE __inline /*!< in ...

  7. Selenium_python自动化环境搭建篇

    説 明: 本篇随笔讲解Selenium+python自动化环境的搭建,此随笔暂不介绍Selenium3,Selenium3需要考虑环境依赖驱动等相关问提比较多一篇随笔没法説完,所以暂不介绍,当然你可以 ...

  8. 20155211 2016-2017-2 《Java程序设计》第2周学习总结

    20155211 2016-2017-2 <Java程序设计>第2周学习总结 教材学习内容总结 通过对教材的阅读,我理解到Java中对于整数,浮点数等类型的定义与c语言基本相同. 对字面常 ...

  9. PGP的原理与使用

    实验名称: PGP的原理与使用 姓名: 刘浩 20155307 任泓霖 20155319 班级: 1553 日期: 2017.10.16 一. 实验环境 Windows虚拟机下使用的是PKZIP2.0 ...

  10. 基于Opencv的人脸检测及识别

    一.实验目的:我这里完成的是,将8张人脸图片(4组,每组两张)存入库中,选取1张图片,程序识别出与其匹配的另一张. 这里介绍分三个步骤完成该工作,①程序读取摄像头.拍照 ②程序从电脑文档中读取图片   ...