按一列以不同的值分组ORACLE

时间:2020-02-24 09:49:21

标签: sql oracle string-aggregation

我有一张桌子:

NUMBER | ELEMENT
-------+----------
1      | Elemento1
1      | Elemento2
1      | Elemento3
2      | Elemento5
2      | Elemento6
2      | Elemento7

我正在按选择搜索组,然后返回下一个:

1 | Elemento1Elemento2Elemento3
2 | Elemento5Elemento6Elemento7

我尝试过:

Select number, element from table group by number;

但是它返回了我not a group by expresion

任何人都知道如果可能的话我该如何实现?

感谢您的时间

1 个答案:

答案 0 :(得分:2)

使用listagg

Select number_, listagg(element) within group (order by element) as elements
From your_table
Group by number_

加油!