在一行中显示一列的多个值 (SQL Oracle)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8508078/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Display multiple values of a column in one row (SQL Oracle)
提问by BvilleBullet
Possible Duplicate:
Is there an Oracle SQL query that aggregates multiple rows into one row?
I'm trying to to create a SQL query that can return data from a table to display multiple values of a column in one row.
我正在尝试创建一个 SQL 查询,该查询可以从表中返回数据以在一行中显示一列的多个值。
For example this is the table setup:
例如,这是表设置:
SEQ ROWSEQNUM ASSISTING_ASSOCIATES
100 2 19332816
100 1 1366344
103 1 12228238
104 1 1366474
I need to query results to look like this:
我需要查询结果如下所示:
SEQ ROWSEQNUM ASSISTING_ASSOCIATES
100 1 1366344; 19332816
103 1 12228238
104 1 1366474
Does anybody have any insight?
有人有任何见解吗?
采纳答案by Dave Costa
I think this ought to work, assuming that for each SEQ
value there is always a row with ROWSEQNUM=1
and the values for ROWSEQNUM
increase sequentially with no gaps.
我认为这应该有效,假设对于每个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