Oracle行转列

表结构及数据展现

Oracle行转列

要实现的效果



实现sql:

select  booktype ,MAX(sys_connect_by_path(t.bookname, '')) as bookname from(
  select a.booktype,a.bookname,row_number() over(PARTITION BY booktype ORDER BY bookname) as rn from a
) t
START WITH rn = 1
CONNECT BY rn = PRIOR rn + 1
AND booktype = PRIOR t.booktype
GROUP BY t.booktype

你可能感兴趣的:(oracle)