【转】 sql统计-关于学生成绩(答案)
sql统计-关于学生成绩(答案)
http://blog.sina.com.cn/s/blog_61380b320100ej9p.html
答案:
1. 计算每个人的总成绩并排名
select name,sum(score) as allscore from stuscore group by name order by allscore
2. 计算每个人的总成绩并排名
select distinct t1.name,t1.stuid,t2.allscore from stuscore t1,
(
select stuid,sum(score) as allscore from stuscore group by stuid
)t2
where t1.stuid=t2.stuid
order by t2.allscore desc
3. 计算每个人单科的最高成绩
select t1.stuid,t1.name,t1.subject,t1.score from stuscore t1,
(
select stuid,max(score) as maxscore from stuscore group by stuid
) t2
where t1.stuid=t2.stuid and t1.score=t2.maxscore
4.计算每个人的平均成绩
select distinct t1.stuid,t1.name,t2.avgscore from stuscore t1,
(
select stuid,avg(score) as avgscore from stuscore group by stuid
) t2
where t1.stuid=t2.stuid
5.列出各门课程成绩最好的学生
select t1.stuid,t1.name,t1.subject,t2.maxscore from stuscore t1,
(
select subject,max(score) as maxscore from stuscore group by subject
) t2
where t1.subject=t2.subject and t1.score=t2.maxscore
6.列出各门课程成绩最好的两位学生
select distinct t1.* from stuscore t1
where t1.stuid in
(select top 2 stuscore.stuid from stuscore where subject = t1.subject order by score desc)
order by t1.subject
7.学号 姓名 语文 数学 英语 总分 平均分
select&nbs
相关文档:
数据类型是数据的一种属性,是数据所表示信息的类型。任何一种语言都有它自己所固有的数据类型,SQL Server提供一下25种固有的数据类型。
SQL Server数据类型一览表
·Binary [(n)]
·Varbinary [(n)]
·Char [(n)]
·Varchar[(n)]
·Nchar[(n)]
·Nvarchar[(n)]
· ......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient; //引用命名空间
namespace DAL
{
/*******************************************************************************
&n ......
错误处理
在SQL Server2000中出现的错误具有以下几个特点:
错误号:每个错误状态都对应唯一的错误号。
错误信息字符串:错误信息提供了有关错误原因的诊断信息。许多错误信息都有替换变量,其中包含一些信息,如产生错误的对象名称。每个错误号都对应唯一的错误信息。
严重度:严重度表示错误的严重程度。 ......
对于有主键自动增长数据库表,在进行分页设置时,我认为还比较不错的是:
SELECT TOP 页大小 *
from TestTable
WHERE (ID >
(SELECT MAX(id)
from (SELECT TOP 页大小*页数 id
  ......