2011-12-14 68 views
2

可能重複:
Is there an Oracle SQL query that aggregates multiple rows into one row?顯示一行一列的多個值(SQL甲骨文)

我試圖創建一個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

還有其他問題(尋求做同樣的事情)已經被回答。退房http://stackoverflow.com/questions/4370820/is-there-a-way-in-oracle-to-join-multiple-row-lines-into-a-single-one-using-t – 2011-12-14 16:38:46

回答

0

我認爲這應該工作,假設對於每個SEQ值總是有一行ROWSEQNUM=1ROWSEQNUM的值依次增加而沒有間隙。

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 
+0

你的假設是正確的我會試試這個感謝真的很快的回覆 – BvilleBullet 2011-12-14 16:39:37