oracle行转列拼接
用法:
LISTAGG('待转的列','分割符号') WITHIN GROUP(ORDER BY 列字段) AS XXX 字段 FROM 表 WHERE 条件 group by 分组条件 ;
WITH TEMP AS (SELECT 'CHINA' NATION, 'GUANGZHOU' CITY FROM DUAL UNION ALL SELECT 'CHINA' NATION, 'SHANGHAI' CITY FROM DUAL UNION ALL SELECT 'CHINA' NATION, 'BEIJING' CITY FROM DUAL UNION ALL SELECT 'USA' NATION, 'NEW YORK' CITY FROM DUAL UNION ALL SELECT 'USA' NATION, 'BOSTOM' CITY FROM DUAL UNION ALL SELECT 'JAPAN' NATION, 'TOKYO' CITY FROM DUAL) SELECT NATION, LISTAGG(CITY, ',') WITHIN GROUP(ORDER BY CITY) AS CITIES FROM TEMP GROUP BY NATION
莫谈他人高薪,且看闲时谁在拼.