listagg wm_concat 行转列

时间:2022-08-25 13:54:11

一、

这个写法和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;

listagg wm_concat 行转列

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;

listagg wm_concat 行转列

二、

不使用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

listagg wm_concat 行转列

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 行转列

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. Child <- many-to-one ->Parent

    网上找到个描述的很精妙的例子 Child   <-   many-to-one   ->Parent         class   Child   {         private   ...

  2. Gulp和Webpack工具的区别

    引用知乎的回答:https://www.zhihu.com/question/37020798 怎么解释呢?因为 Gulp 和 browserify / webpack 不是一回事 Gulp应该和Gr ...

  3. windows文件关联、打开方式列表之修改注册表攻略

    这里全是修改注册表的方式.网上找了半天,有的仅有添加文件关联的方法,却没有添加到打开方式列表里面的方法:有的有添加到文件列表的方法,却是使 用控制面板->文件夹选项的.好难得才找齐所有,从添加文 ...

  4. JS 复制对象

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs& ...

  5. XMPP框架下微信项目总结(4)重新连接服务器

    xmpp 很多功能是面向模块开发的 例如电子名片 无须自己去写请求的代码XMPP(文件)->Extension(存放的是各个模块)->Reconnect(自动连接模块)          ...

  6. JAVA复制网络图片到本地

    import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.io.Out ...

  7. VSFTPD添加用户

    VSFTPD的安装网上有很多教程这里就不多说了,这里主要是针对做主机空间服务的朋友在安装好vsftpd后如何为用户增加ftp账号 先来看一看我们一般在*inux系统下面如何增加用户的 #adduser ...

  8. H TML5 之 (1) 初识HTML5

    新特性 HTML5 中的一些有趣的新特性: 用于绘画的 canvas 元素 用于媒介回放的 video 和 audio 元素 对本地离线存储的更好的支持 新的特殊内容元素,比如 article.foo ...

  9. Visual Studio 2017正式版发布全纪录

    又是一年发布季,微软借着Visual Studio品牌20周年之际,于美国太平洋时间2017年3月7日9点召开发布会议,宣布正式发布新一代开发利器Visual Studio 2017.同时发布的还有 ...

  10. mybatis获取批量插入的主键自增id

    一.写一个实体类 public class UserInfo { private long userId; private String userAccount; private String use ...