【转】 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
相关文档:
第一种:
SELECT
CASE
WHEN
price IS NULL THEN
'Not yet priced'
WHEN
price < 10 THEN
'Very Reasonable Title'
WHEN
price >= 10 AND
price < 20 THEN
'Coffee Table Title'
EL ......
1. 程序如下:
string str = "Create Database " + "DBname";
string con = "Data Source=10.0.0.249\\sql2005;Initial Catalog=master;Persist Security Info=True;User ID=sa;Password=sa";
&n ......
错误处理
在SQL Server2000中出现的错误具有以下几个特点:
错误号:每个错误状态都对应唯一的错误号。
错误信息字符串:错误信息提供了有关错误原因的诊断信息。许多错误信息都有替换变量,其中包含一些信息,如产生错误的对象名称。每个错误号都对应唯一的错误信息。
严重度:严重度表示错误的严重程度。 ......
Sql时间函数
一、sql server日期时间函数
Sql Server中的日期与时间函数
1. 当前系统日期、时间
select getdate()
2. dateadd 在向指定日期加上一段时间的基础上,返回新的 datetime 值
例 ......