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...) 在网上找了相关的知识但不是很明白 请各位老大赐教
等效于这句: 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,总计
sum(stuScroe)over(partition by stuName) 总计
的写法吗
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,总计