oracle 合并记录
selete a.country, b.city from table1 a,table b where a.country=b.country 这条sql结果如下,
-------------------------------------------------
country city
日本 东京
日本 大坂
中国 上海
中国 北京
中国 深圳
---------------------------------------------------但是以下才是我想要的结果,怎么实现这条sql,注意城市是动态的
country city
日本 东京, 大坂
中国 上海,北京, 深圳
谢谢!
[解决办法]
with t as(select '日本' country,'东京' city from dualunion allselect '日本','大坂' from dualunion allselect '中国','上海' from dualunion allselect '中国','北京' from dualunion allselect '中国','深圳' from dual)select country,wm_concat(city) from t group by countryCOUNTRY WM_CONCAT(CITY)------- --------------------------------------------日本 东京,大坂中国 上海,深圳,北京
[解决办法]
with t as (
select '日本' as country, '东京' as city from dual
union all
select '日本', '大坂' from dual
union all
select '中国', '上海' from dual
union all
select '中国', '北京' from dual
union all
select '中国', '深圳' from dual
)
select country,wm_concat(city) from t
group by country
--
日本东京,大坂
中国上海,深圳,北京