后台表存储格式--第一行是表栏位名称 :
emloyee score subject 001 97 Chinese
001 100 Mathematics 001 89 Other 002 87 Chinese
002 96 Mathematics 002 78 Other一实现:如何在C#中用Gridviw绑定出以下格式
Chinese Mathematics Other001 97 100 89
002 87 96 78二实现求每位的平均分(用二维数组求)~~~~以上,在线等。虚心学习中!!!
emloyee score subject 001 97 Chinese
001 100 Mathematics 001 89 Other 002 87 Chinese
002 96 Mathematics 002 78 Other一实现:如何在C#中用Gridviw绑定出以下格式
Chinese Mathematics Other001 97 100 89
002 87 96 78二实现求每位的平均分(用二维数组求)~~~~以上,在线等。虚心学习中!!!
就解决问题了
Declare @sql varchar(2000)
Set @sql = 'Select emloyee as 姓名'
Select @sql = @sql + ',sum(case Subject when '''+Subject+''' then score else 0 end) ['+Subject+']'
from (select distinct Subject from tableName) as tName
Select @sql = @sql+' from tableName group by emloyee'
Exec (@sql)--2
Declare @sql2 varchar(2000)
Set @sql2 = 'Select emloyee as 姓名,(0'
Select @sql2 = @sql2 + ' + sum(case Subject when '''+Subject+''' then score else 0 end) '
from (select distinct Subject from tableName) as tName
Select @sql2 = @sql2 + ') / (0'
Select @sql2 = @sql2 + ' + sum(case Subject when '''+Subject+''' then 1 else 0 end) '
from (select distinct Subject from tableName) as tName2
Select @sql2 = @sql2+') as avg from tableName group by emloyee'
Exec (@sql2)