【SQL积累】查询成绩语句,带总分
2010-02-06 18:20
330 查看
declare @sql varchar(8000)
declare @examid varchar(10)
declare @claid varchar(10)
set @claid='60'
set @examid='151'
Set @sql = 'Select m.pargid,c.nickname as parname,c.mobile,a.Name as stuname'
Select @sql = @sql + ',max(case d.coursename when '''+d.coursename+''' then convert(varchar(50),isnull(a.score,0)) else ''0'' end) ['+d.coursename+']'
from (select distinct x.coursename from score_course x,score_examcourse y where x.id=y.courseid and y.examid=@examid) as d
Select @sql = @sql+',sum(a.score) as sumscore
from score_detail a,score_examcourse b,base_user c,score_course d,base_formaluser m
where m.stugid=a.gid and m.pargid=c.gid and a.examcouid=b.id and b.courseid=d.id and b.examid='+@examid+' and a.claid='+@claid+'
group by a.name,a.gid ,m.pargid,c.nickname,c.mobile'
Exec (@sql)
declare @examid varchar(10)
declare @claid varchar(10)
set @claid='60'
set @examid='151'
Set @sql = 'Select m.pargid,c.nickname as parname,c.mobile,a.Name as stuname'
Select @sql = @sql + ',max(case d.coursename when '''+d.coursename+''' then convert(varchar(50),isnull(a.score,0)) else ''0'' end) ['+d.coursename+']'
from (select distinct x.coursename from score_course x,score_examcourse y where x.id=y.courseid and y.examid=@examid) as d
Select @sql = @sql+',sum(a.score) as sumscore
from score_detail a,score_examcourse b,base_user c,score_course d,base_formaluser m
where m.stugid=a.gid and m.pargid=c.gid and a.examcouid=b.id and b.courseid=d.id and b.examid='+@examid+' and a.claid='+@claid+'
group by a.name,a.gid ,m.pargid,c.nickname,c.mobile'
Exec (@sql)
相关文章推荐
- 查询每个学生的各科成绩sql语句
- sql语句多表查询(学生表/课程表/教师表/成绩表 )
- SQL 查询语句积累
- 营配数据质量核查,关于营销mis系统与配电gis系统里面的sql语句查询,做为积累使用,下次就不用重复写同样的语句了。
- SQL查询语句积累
- 一条SQL语句查询出成绩名次排名
- sql查询每个学生的最高成绩mysql语句
- sql语句多表查询(学生表/课程表/教师表/成绩表 )
- 用一句SQL语句查询成绩优良中差的人数
- 只有两个字段用一个sql语句查询出某个学生的姓名、成绩以及在表中的排名
- sql语句多表查询(学生表/课程表/教师表/成绩表 )
- SQL 查询语句积累
- sql语句多表联合查询(学生表/课程表/教师表/成绩表 )
- 常用的sql语句,学生、课程、成绩、教师表的查询
- 一条SQL语句查询出成绩名次 排名 (转)
- SQL语句多表查询(学生表/课程表/教师表/成绩表 ){转载}
- 关于学生成绩查询的几个SQL语句
- SQL 一些有用的查询语句积累
- SQL语句积累1:自身查询、区间查询、同号排查
- SQL 语句 知识积累----------子查询实例