且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在一行中显示一列的多个值(SQL Oracle)

更新时间:2021-11-07 22:24:19

我认为这应该起作用,假设对于每个SEQ值,总会有一行带有ROWSEQNUM=1的行,并且ROWSEQNUM的值按顺序增加没有缝隙.

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.

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