表名  test
其中test_a1,test_a2,test_a3字段名
     test_a1 test_a12      test_a3
       ss            dd        ff
       sss  ddd       fff
       s             b        v
       s             g        h
       s                     y
用一条sql使结果显示为
     test_a1 test_a12      test_a3
       ss            dd        ff
       sss   ddd        fff
       s            b,g,t        v,h,y
求一条sql语句?????

解决方案 »

  1.   

    楼主看看我的blog吧,把纵向记录横向显示的问题,和你的差不多,参考一下:
    http://blog.csdn.net/kinglht
      

  2.   

    这种要用存储过程来实现了,根据test_a1的纪录数,重新组合test_a2,test_a3的内容,最后再显示出来,因为你这个里面test_a1重复的纪录数是不定的
      

  3.   

    我觉得主要是解决这个问题,不在于通过什么途径就一条sql语句在oracle中没有办法做到,需要通过过程来处理。如果是这样还不如通过上层的程序处理来得简单。
      

  4.   

    看看这个是不是你想要的。SQL> select * from a;I NAM
    - ---
    1 aa
    1 bb
    1 cc
    2 xx
    2 yy
    3 zz
    3 mm select max(substr((sys_connect_by_path(name,',')),2)) cola
     from (
     select id,name,
            rownum rnum,
            row_number() over(partition by id order by id) rn1
     from a
     )
     start with rn1=1
     connect by rnum-1=prior rnum
     group by id
    ;--------------------------------------------------------------------------------aa,bb,cc
    xx,yy
    zz,mm