declare @sql varchar(4000),@nclassid int,@nexamid int select @sql='' select @nclassid=38 select @nexamid=19 select @sql=@sql+'max(case scoursename when '''+scoursename+''' then descore else 0 end) '+scoursename+',' from (select distinct scoursename from t_card_course where id in (select ncourseid from t_card_examcou where nclassid =+@nclassid and nexamid=+@nexamid )) a exec(' select nclassid, name 姓名,'+ @sql+ 'sum(descore) 总分 into #temp from ( select b.nclassid,b.name,a.descore,c.scoursename from t_card_score a,t_stu b,t_card_course c,t_card_examcou d where a.nstuid=b.id and a.ncouexamid in (select id from t_card_examcou where nclassid in (select id from t_card_class where ngradeid =(select ngradeid from t_card_class where id='+@nclassid+' and nschoolid=(select nschoolid from t_card_class where id='+@nclassid+'))) and nexamid='+@nexamid+' ) and a.ncouexamid=d.id and d.ncourseid=c.id group by b.nclassid,b.name,a.descore,c.scoursename )as a group by name,nclassid select *,班级名次=(select count(总分) from #temp where 总分>y.总分 and nclassid=y.nclassid)+1 into #tempclass from #temp y select *,年级名次 =(select count(总分) from #tempclass where 总分>x.总分)+1 into #tempok from #tempclass x where nclassid ='+@nclassid+' order by 班级名次 alter table #tempok drop column nclassid select * from #tempok ') 这些查询我不知道下一步怎么改了,所以就想再客户端通过DataTable改动,但是不得其法,无论是SQL语句还是在客户端都可以。
select @sql=@sql+'max(case scoursename when '''+scoursename+''' then descore else 0 end) '+scoursename+','
from (select distinct scoursename from t_card_course where id in (select ncourseid from t_card_examcou where nclassid =+@nclassid and nexamid=+@nexamid )) a
exec('
select nclassid, name 姓名,'+ @sql+ 'sum(descore) 总分
into #temp
from (
select b.nclassid,b.name,a.descore,c.scoursename
from t_card_score a,t_stu b,t_card_course c,t_card_examcou d
where a.nstuid=b.id and a.ncouexamid in
(select id from t_card_examcou where nclassid in (select id from t_card_class where ngradeid =(select ngradeid from t_card_class where id='+@nclassid+' and nschoolid=(select nschoolid from t_card_class where id='+@nclassid+'))) and nexamid='+@nexamid+' )
and a.ncouexamid=d.id and d.ncourseid=c.id group by b.nclassid,b.name,a.descore,c.scoursename )as a
group by name,nclassid
select *,班级名次=(select count(总分) from #temp where 总分>y.总分 and nclassid=y.nclassid)+1 into #tempclass from #temp y
select *,年级名次 =(select count(总分) from #tempclass where 总分>x.总分)+1 into #tempok from #tempclass x where nclassid ='+@nclassid+' order by 班级名次
alter table #tempok drop column nclassid
select * from #tempok
')
这些查询我不知道下一步怎么改了,所以就想再客户端通过DataTable改动,但是不得其法,无论是SQL语句还是在客户端都可以。
毕竟sql相对麻烦一些,否则就不会有CLR了。
問一下你是sql2000還是2005,給我表的結構幫你重寫
然后通过遍历上面的gridview赋值。
比如化学平均分就是第二列的汇总/个数。
以此类推啊。