可能重复:
Is there an Oracle SQL query that aggregates multiple rows into one row?
我正在尝试创建一个SQL查询,该查询可以从表中返回数据,以在一行中显示列的多个值。
例如,这是表格设置:
SEQ ROWSEQNUM ASSISTING_ASSOCIATES
100 2 19332816
100 1 1366344
103 1 12228238
104 1 1366474
我需要查询结果如下:
SEQ ROWSEQNUM ASSISTING_ASSOCIATES
100 1 1366344; 19332816
103 1 12228238
104 1 1366474
有人有任何见解吗?
答案 0 :(得分:0)
我认为这应该有用,假设对于每个SEQ
值,总会有一行ROWSEQNUM=1
,而ROWSEQNUM
的值会按顺序增加而没有间隙。
select seq, min(rowseqnum), max(assoc_list)
from (
select seq, rowseqnum, sys_connect_by_path(assisting_associate,';') assoc_list
from assoc_table
start with rowseqnum=1
connect by seq = prior seq and rowseqnum = prior rowseqnum + 1
)
group by seq