1

Till now i haven't got a need to post a query, almost everything is available. This is my first question.

I have a different requirement, I have the below table name say alarmdb

------------------INT_ID----------------------------------------------------- ALARM_NUMBER----------------------------

             101212121                               7762
             101212121                               8212
             101212121                               3423
             101313131                               7734
             101313131                               7743

Basically its kind of grouping, and pivoting. Final output can be like this.

------------------INT_ID----------------------------------------------------- ALARM_NUMBER----------------------------

             101212121                           7762,8212,3423
             101313131                               7734,7743

Kind of shrinking many cells data into one.

Can anyone please suggest.

4

1 回答 1

2

根据您的 Oracle 版本,您有不同的选择。

您可以LISTAGG用于 Oracle 11g+:

select int_id,
  listagg(alarm_number, ', ') within group (order by int_id) as alarm_number
from yourtable
group by int_id;

请参阅带有演示的 SQL Fiddle

或者您可以wm_concat() 用于早期版本:

select int_id,
  wm_concat(alarm_number) as alarm_number
from yourtable
group by int_id
于 2013-04-09T17:49:59.113 回答