Oracle SQL将一列的值放在一行中 [英] Oracle SQL put values of a column in one row
本文介绍了Oracle SQL将一列的值放在一行中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个查询要返回3列
I have a query were im returning a 3 columns
ID NUMBER LETTER
123 1 a
124 2 b
123 1 c
123 1 d
我想做的是像
ID NUMBER LETTER
123 1 a,c,d
当我的ID和NUMBER列相同时,是一个值和t
when I the ID and NUMBER column is the same is one value and t
推荐答案
In Oracle 11g, you can use the LISTAGG() function:
select id,
number,
listagg(letter, ', ') within group(order by id, number) as letter
from yourtable
group by id, number;
请参见带有演示的SQL小提琴
这篇关于Oracle SQL将一列的值放在一行中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文