LISTAGG函数怎么使用
这篇文章主要介绍“LISTAGG函数怎么使用”,在日常操作中,相信很多人在LISTAGG函数怎么使用问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”LISTAGG函数怎么使用”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
创新互联公司专业提供成都主机托管四川主机托管成都服务器托管四川服务器托管,支持按月付款!我们的承诺:贵族品质、平民价格,机房位于中国电信/网通/移动机房,服务器托管德阳服务有保障!
LISTAGG函數 Oracle 11.2之後推出的:字符串聚合
字符串聚合就是按照分组把多行数据串联成一行,以下面的结果集为例:
11.2之前有WMSYS.WM_CONCAT函數,不過是非文檔說明的
舉個列子
為實現,同一類不同行數據 在 一行中顯示出來,可以使用
wmsys.wm_concat(a.FAILURE_DESC||'-'|| a.FAILURE_QTY)
或
LISTAGG(a.FAILURE_DESC||'-'|| a.FAILURE_QTY)WITHIN GROUP(ORDER BY NULL)
select a.shift, a.work_order, a.machineid, a.date_work, a.part_name, a.model_name,a.CUSTOMER_NAME,
a.model_serial, a.QTY,TO_CHAR(wmsys.wm_concat(a.FAILURE_DESC||'-'|| a.FAILURE_QTY))from (
SELECT a.shift, a.work_order, a.machineid, a.date_work, a.part_name, a.model_name,a.CUSTOMER_NAME,
a.model_serial, SUM (a.pass_qty) QTY,b.FAILURE_DESC,b.FAILURE_QTY
FROM (SELECT a.shift, a.work_order, a.machineid,c.CUSTOMER_NAME,
CASE WHEN a.shift = 'N' AND a.time_section <8
THEN TO_CHAR (TO_DATE (a.work_date, 'yyyy/mm/dd') - 1,'yyyymmdd')
ELSE a.work_date
END AS date_work,
a.pass_qty, b.part_name, a.model_name, b.model_serial
FROM (SELECT work_date, work_order, machineid, model_name,
CASE WHEN time_section > 8
AND time_section <=20
THEN 'D'
ELSE 'N'
END shift,time_section, pass_qty
FROM wip_d_machine_uph) a,mms.bdm_s_product b,BDM_S_CUSTOMER c
WHERE a.model_name = b.part_no and b.CUSTOMER_ID = c.CUSTOMER_ID)a,
(select a.*,
CASE WHEN time_section > 8 AND time_section <= 20
THEN 'D'
ELSE 'N'
END shift ,
CASE WHEN time_section > 8
AND time_section<= 20
THEN to_char(FAILURE_INIPUT_TIME,'yyyymmdd')
ELSE to_char(FAILURE_INIPUT_TIME-1,'yyyymmdd')
END work_date
from OEE_D_FAILURE_INPUT a) b
where a.WORK_ORDER = b.WORK_ORDER(+)
and a.model_name = b.PART_NO(+)
and a.MACHINEID = b.MACHINE_ID(+)
and a.DATE_WORK = b.work_date(+)
and a.shift=b.shift(+)
and a.DATE_WORK>='20130101' and a.DATE_WORK<='20130203' and a.CUSTOMER_NAME ='DELL'
GROUP BY a.shift,a.work_order,a.machineid,a.date_work,a.part_name,a.model_name,a.model_serial,a.CUSTOMER_NAME,b.FAILURE_DESC,b.FAILURE_QTY) a
GROUP BY a.shift,a.work_order,a.machineid,a.date_work,a.part_name,a.model_name,a.qty,a.model_serial,a.CUSTOMER_NAME
到此,关于“LISTAGG函数怎么使用”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!
网站名称:LISTAGG函数怎么使用
网站链接:http://azwzsj.com/article/jcoceo.html