selete a.country, b.city from table1 a,table b where a.country=b.country      这条sql结果如下,-------------------------------------------------------------------------------------
  country        city       
   日本          东京            
   日本          大坂
   中国          上海
   中国          北京
   中国          深圳---------------------------------------------------但是以下才是我想要的结果,怎么实现这条sql,注意城市是动态的   country         city       
   日本          东京, 大坂
   中国          上海,北京, 深圳
谢谢!

解决方案 »

  1.   

    with t as(
    select '日本' country,'东京' 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
    COUNTRY WM_CONCAT(CITY)
    ------- --------------------------------------------------------------------------------
    日本    东京,大坂
    中国    上海,深圳,北京
      

  2.   

    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--
    日本 东京,大坂
    中国 上海,深圳,北京
      

  3.   

    谢谢楼上两位,以用你们提供的方法解决了,tks!