首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

oracle 合并记录,该如何解决

2012-04-21 
oracle 合并记录selete a.country, b.city from table1 a,table b where a.countryb.country这条sql结果

oracle 合并记录
selete a.country, b.city from table1 a,table b where a.country=b.country 这条sql结果如下,

-------------------------------------------------
  country city  
  日本 东京  
  日本 大坂
  中国 上海
  中国 北京
  中国 深圳

---------------------------------------------------但是以下才是我想要的结果,怎么实现这条sql,注意城市是动态的

  country city  
  日本 东京, 大坂
  中国 上海,北京, 深圳








谢谢!

[解决办法]

SQL code
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

--
日本东京,大坂
中国上海,深圳,北京

热点排行