sql

区域        省份        城市 
华北        河北        石家庄 
华北        河北        秦皇岛 
华北        山西        太原 
华北        内蒙古      包头 
东北        辽宁        大连 
东北        吉林        吉林 
东北        辽宁        沈阳 
东北        辽宁        鞍山 
华南        湖南        张家界 
华南        广东        广州 
求sql, 
华北      河北,山西,内蒙古 
东北      辽宁,吉林 
华南      湖南,广东

解决方案 »

  1.   

    select area,wmsys.wm_concat(province) from (select distinct area,province from table) group by area;
      

  2.   


    select 区域  ,
    substr(max(sys_connect_by_path(省份,',')),2) 省份,
    from ( select 
    区域,省份, row_number() over(order by 省份) rn
    from re_room t1  ) 
    )
    start with rn=1
    connect by rn-1=prior rn
    group by 区域  
      

  3.   


    select 区域  ,
    substr(max(sys_connect_by_path(省份,',')),2) 省份,
    from ( select 
    区域,省份, row_number() over(order by 省份) rn
    from 表名  ) 
    )
    start with rn=1
    connect by rn-1=prior rn
    group by 区域