一、

这个写法和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. 洛谷P4602 [CTSC2018]混合果汁(主席树)

    题目描述 小 R 热衷于做黑暗料理,尤其是混合果汁. 商店里有 nn 种果汁,编号为 0,1,\cdots,n-10,1,⋯,n−1 . ii 号果汁的美味度是 d_idi​ ,每升价格为 p_ipi ...

  2. scrapy管道MySQL简记

    import pymysqlfrom scrapy.exceptions import DropItemimport time class ErshouchePipeline(object): def ...

  3. ionic ios 打包 真机测试常见问题

    1.ionic 项目在windows下正常打包安卓包时  迁移到mac下打包ios时  不需要复制平台目录platforms即可  不用再mac下去安装各种插件信息 2.ionic 下不能访问api信 ...

  4. 10JavaScript作用域

    (作用域可访问变量的集合) 1.JavaScript 作用域 在 JavaScript 中, 对象和函数同样也是变量. 在 JavaScript 中, 作用域为可访问变量,对象,函数的集合. Java ...

  5. Ruby中Enumerable模块的一些实用方法

    我在查看 Array 类和 Hash 类的祖先链的时候都发现了 Enumerable,说明这两个类都mixin了Enumerable模块.Enumerable模块为集合型类提供了遍历.检索.排序等方法 ...

  6. homebrew 使用心得

    ''' 安装anaconda 安装命令: brew search anaconda brew cask install anaconda 添加环境变量: vi ~/.bash_profile expo ...

  7. PTA(BasicLevel)-1009 说反话

    一 .问题描述       原题描述 给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出.不同于字符串逆序,这里需要的是将字符串中的单词顺序翻转. 输入样例: Hello World Here ...

  8. 理解 ajax、fetch和axios

    背景 ajax fetch.axios 优缺点 ajax基于jquery,引入时需要引入庞大的jquery库,不符合当下前端框架,于是fetch替代了ajax 由于fetch是比较底层,需要我们再次封 ...

  9. DP_括号匹配序列问题

    括号匹配问题 简单括号匹配问题是给出字符串,判断字符串中的括号是否匹配,此类问题核心解决方案就是利用栈的后进先出的特性,从左到右依次遍历字符串,遇左括号进栈,遇右括号将其与栈顶元素配对,若能配对,则栈 ...

  10. js scroll nav

    http://jsfiddle.net/cse_tushar/Dxtyu/141/http://ironsummitmedia.github.io/startbootstrap-scrolling-n ...