将许多数据合并为一个数据

时间:2018-05-23 03:46:51

标签: vb.net oracle

我有这样的数据

 CCSKIYEARDOULE     |    CCSKIYEAR
 ------------------------------------ 
 92-93              |     92 
 92-93              |     93
 94-95              |     94
 94-95              |     95
 96-97              |     97

但我想要像这样的输出

 CCSKIYEARDOULE     |    CCSKIYEAR
 ------------------------------------ 
 92-93              |     92, 93
 94-95              |     94, 95
 96-97              |     97

我已经使用了group_concat,但是我收到了错误" ORA-00904:" GROUP_CONCAT":无效的标识符"

这是我的代码

SELECT GROUP_CONCAT(CCSKIYEARDOUBLE), CCSKIYEAR FROM CCS2_TBL_KI2 GROUP BY CCSKIYEARDOUBLE ORDER BY CCSKIYEAR ASC;

1 个答案:

答案 0 :(得分:1)

Below check below query 

create table CCSK
 (CCSKIYEARDOULE varchar2(10),
 CCSKIYEAR number);

 begin
 insert into CCSK values ('92-93',92);
 insert into CCSK values ('92-93',93);
 insert into CCSK values ('94-95',94);
 insert into CCSK values ('94-95',95);
 insert into CCSK values ('96-97',97);
end;



 select CCSKIYEARDOULE,listagg(CCSKIYEAR,',')
 from CCSK
 group by CCSKIYEARDOULE;