一、

这个写法和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. LNMP web服务的安装

    第1章 安装Nginx 环境: 系统:CentOS6.5 软件:nginx-1.6.3     mysql-5.5.49    php-5.5.32 1.1 Nginx官网 http://nginx. ...

  2. Bugku一段base64

    本文转自:本文为博主原创文章,如有转载请注明出处,谢谢. https://blog.csdn.net/pdsu161530247/article/details/74640746 链接中高手给出的解题 ...

  3. 20155204第4次实验《Android程序设计》实验报告

    20155204第四次实验报告 一.实验内容及步骤 1.Android Stuidio的安装测试: 安装 Android Stuidio 完成Hello World, 要求修改res目录中的内容,He ...

  4. 20155319 2016-2017-2《Java程序设计》课程总结

    20155319 2016-2017-2<Java程序设计>课程总结 每周作业链接 预备作业1:亦师亦友--我所期望的师生关系,对专业的认识与期望等 预备作业2:没有了自主,学习的小船说翻 ...

  5. #20155331 2016-2017-2 《Java程序设计》第3周学习总结

    20155331 2016-2017-2 <Java程序设计>第3周学习总结 教材学习内容总结 第四章 程序中的类由两个部分组成:属性和方法.属性对应的是对象的特征:方法对应的是对象的行为 ...

  6. combobox添加复选框

    问题: 需求提出要做一个下拉框可以多选的 解决方案: //机构树 function initOrgTree() { $('#reportOrg').combobox({ width: 200, edi ...

  7. day1 ORM

    ORM对象关系映射 映射关系: 表名 <-------> 类名 字段 <-------> 属性 表记录 <------->类实例对象 class Customer( ...

  8. CF 833 B. The Bakery

    B. The Bakery http://codeforces.com/contest/833/problem/B 题意: 将一个长度为n的序列分成k份,每份的cost为不同的数的个数,求最大cost ...

  9. ELKStack入门篇(一)之ELK部署和使用

    一.ELKStack简介 1.ELK介绍 中文指南:https://www.gitbook.com/book/chenryn/elk-stack-guide-cn/details ELK Stack包 ...

  10. idea 新建 maven项目遇到的一些问题

    idea创建好了maven项目之后,需要先在项目中添加 Web,这里创建Web时就会要求fix一个Artifacts,新建即可,然后面板设置默认即可(shift+ctrl+alt+s 打开面板): 然 ...