两个表,主从关系,A表(主表),B表(从表)
A              
字段1 字段2
1      1
2      2
3      3
B
字段1 字段21 字段3
1      1      001
1      2      002
1      3      003
查询结果是
字段1   字段合成
1       001;002;003 
2       
3

解决方案 »

  1.   

    select a.col1,wm_concat(b.col3)
    from a,b
    where a.col1=b.col1(+)
    group by a.col1
      

  2.   

    wildwave  看来你那合并列的没有起来效果!!!
    哈哈!!在写一次,然后在版主置顶!!!
      

  3.   

    select a.col1,replace(wm_concat(b.col3),',',';')newstr
    from a,b 
    where a.col1=b.col1(+) 
    group by a.col1这是10g以上的代码
    如果是9i的
    select col1,substr(max(sys_connect_by_path(col3,';')),2)newstr
    from(
      select a.col1,b.col3,
        row_number()over(partition by a.col1 order by b.col2)rn
      from a,b 
      where a.col1=b.col1(+) )
    connect by prior col1=col1 and prior rn=rn-1
    start with rn=1
    group by col1
      

  4.   

    为什么不用?字段要聚合就需要聚合函数,要分组就必须group by
    如果外面不聚合也必须在子查询里聚合,一样的