Home > Database > Mysql Tutorial > Oracle 按照日期先后顺序连接字符串

Oracle 按照日期先后顺序连接字符串

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:01:12
Original
955 people have browsed it

//我们都知道wm_concat()函数具有连接字符串的功能, //下面是一个实例: with t as( select

//我们都知道wm_concat()函数具有连接字符串的功能,  
//下面是一个实例:  
with t as(  
     select 'A' 井号,to_date('2011-1-10','yyyy-mm-dd') 汇报日期,'良好1' 工作情况 from dual union all  
     select 'A',to_date('2011-1-2','yyyy-mm-dd'),'良好2' from dual union all  
     select 'A',to_date('2010-1-3','yyyy-mm-dd'),'良好3' from dual union all  
     select 'B',to_date('2011-1-4','yyyy-mm-dd'),'良好4' from dual union all  
     select 'B',to_date('2010-1-5','yyyy-mm-dd'),'良好5' from dual union all  
     select 'A',to_date('2011-1-16','yyyy-mm-dd'),'良好6' from dual)  
select 井号,wm_concat(汇报日期||工作情况) 工作情况  
from t  
group by 井号  
/  
井号 工作情况  
---- --------------------------------------------------------------------------------  
A    2011-01-10良好1,2011-01-02良好2,2011-01-16良好6,2010-01-03良好3  
B    2011-01-04良好4,2010-01-05良好5  
//  
//从结果我们可以看出来,,字符串的连接是按照A的行序号,从小到大的连接  
//对于同一个行号,从左到右的连接;  
//  
//如果我们想要按照日期的先后顺序来进行连接,那我们该怎么做呢?  
//具体请看下面的代码:  
select 井号, max(工作情况)  as 工作情况   
from (  
     select 井号,  
            wm_concat(汇报日期||工作情况)over(partition by 井号 order by 汇报日期) 工作情况   
      from t)  
group by 井号  
/  
井号 工作情况  
---- --------------------------------------------------------------------------------  
A    2010-01-03良好3,2011-01-02良好2,2011-01-10良好1,2011-01-16良好6  
B    2010-01-05良好5,2011-01-04良好4  
-- 

linux

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template