问题描述
后台表存储格式--第一行是表栏位名称:emloyeescoresubject00197Chinese001100Mathematics00189Other00287Chinese00296Mathematics00278Other一实现:如何在C#中用Gridviw绑定出以下格式ChineseMathematicsOther0019710089002879678二实现求每位的平均分(用二维数组求)~~~~以上,在线等。虚心学习中!!!
解决方案
解决方案二:
你搜索一下SQL行列转换就解决问题了
解决方案三:
--1Declare@sqlvarchar(2000)Set@sql='Selectemloyeeas姓名'Select@sql=@sql+',sum(caseSubjectwhen'''+Subject+'''thenscoreelse0end)['+Subject+']'from(selectdistinctSubjectfromtableName)astNameSelect@sql=@sql+'fromtableNamegroupbyemloyee'Exec(@sql)--2Declare@sql2varchar(2000)Set@sql2='Selectemloyeeas姓名,(0'Select@sql2=@sql2+'+sum(caseSubjectwhen'''+Subject+'''thenscoreelse0end)'from(selectdistinctSubjectfromtableName)astNameSelect@sql2=@sql2+')/(0'Select@sql2=@sql2+'+sum(caseSubjectwhen'''+Subject+'''then1else0end)'from(selectdistinctSubjectfromtableName)astName2Select@sql2=@sql2+')asavgfromtableNamegroupbyemloyee'Exec(@sql2)