1. 程式人生 > >Oracle 聚合多個欄位

Oracle 聚合多個欄位

SELECT country,max(substr(city,2)) city
   FROM
(SELECT country,sys_connect_by_path(city,',') city
FROM 
(SELECT country,city,country||rn rchild,country||(rn-1) rfather
   FROM 
   (SELECT   test.country ,test.city,row_number() over (PARTITION BY test.country ORDER BY 

test.city) rn 
   FROM test))
CONNECT BY PRIOR rchild=rfather START WITH rfather LIKE '%0')

GROUP BY country