select stuName,数学,语文,英语,总计
from (select *,sum(stuScroe)over(partition by stuName) 总计 from a) a
    pivot(max(stuScroe) for stuClass in(数学,语文,英语))b代码中的over(partition by ...),和pivot(.. for...)
在网上找了相关的知识但不是很明白
请各位老大赐教

解决方案 »

  1.   

    pivot sql 2005的  msdn上面有
      

  2.   

    这个是 sql2005 带的行转列
      

  3.   


    sum(stuScroe)over(partition by stuName) 总计
    的写法吗
      

  4.   

    http://topic.csdn.net/u/20090905/09/dc24baf9-2f7e-4469-a5dc-a546a595529f.html?7759
      

  5.   

    等效于这句:
    select stuName,
        max(case stuClass when '数学' then stuScroe end) '数学' ,
        max(case stuClass when '语文' then stuScroe end) '语文' ,
        max(case stuClass when '英语' then stuScroe end) '英语' ,
        总计
    from (select *,总计=(select sum(stuScroe) from A where stuName=t.stuName) from A t) a
    group by stuName,总计