表结构内容如下
studentid   studentname  score  pmclass  pmgrade   subject
1001        a             80    1          2       化学
1001        a             95    1          1       物理
.......................................................
1002        b             85    1          1       化学
1002        b             90    2          2       物理
.......................................................
在页面上显示为
学号      姓名         化学        物理   .     ..     ..
1001      a         80,1,2       95,1,1     ..     ..
1002      b         85,1,1       90,2,2     ...    ..
.........................................................
一次考试有多个学生参加,一次考试有多门课程
请问高手这个sql语句该怎么写呢?谢谢

解决方案 »

  1.   

    select a.studentid,a.studentname decode(a.subject,'化学',a.score|","|a.pmclass|","|a.pmgrade),decode(a.subject,'物理',a.score|","|a.pmclass|","|a.pmgrade),... ...from tbname a
    或者用case a.subject when '化学' a.score|","|a.pmclass|","|a.pmgrade end这种应该也可以
      

  2.   

    http://blog.csdn.net/heyixiang/archive/2005/07/06/415444.aspx问题类似,参考上面。