Chinaunix首页 | 论坛 | 博客
  • 博客访问: 592984
  • 博文数量: 68
  • 博客积分: 5070
  • 博客等级: 大校
  • 技术积分: 1312
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-11 14:20
文章分类

全部博文(68)

文章存档

2011年(3)

2010年(30)

2009年(17)

2008年(18)

我的朋友

分类: Mysql/postgreSQL

2010-01-16 17:10:27

21、查询不同老师所教不同课程平均分从高到低显示
 
SELECT max(Z.T#) AS 教师ID,MAX(Z.Tname) AS 教师姓名,C.C# AS 课程ID,MAX(C.Cname) AS 课程名称,AVG(Score) AS 平均成绩
   
FROM SC AS T,Course AS C ,Teacher AS Z
   
where T.C#=C.C# and C.T#=Z.T#
 
GROUP BY C.C#
 
ORDER BY AVG(Score) DESC
22、查询如下课程成绩第 3 名到第 6 名的学生成绩单:企业管理(001),马克思(002),UML (003),数据库(004
   
[学生ID],[学生姓名],企业管理,马克思,UML,数据库,平均成绩
   
SELECT  DISTINCT top 3
      SC.S#
As 学生学号,
        Student.Sname
AS 学生姓名 ,
      T1.score
AS 企业管理,
      T2.score
AS 马克思,
      T3.score
AS UML,
      T4.score
AS 数据库,
     
ISNULL(T1.score,0) + ISNULL(T2.score,0) + ISNULL(T3.score,0) + ISNULL(T4.score,0) as 总分
     
FROM Student,SC  LEFT JOIN SC AS T1
                     
ON SC.S# = T1.S# AND T1.C# = '001'
           
LEFT JOIN SC AS T2
                     
ON SC.S# = T2.S# AND T2.C# = '002'
           
LEFT JOIN SC AS T3
                     
ON SC.S# = T3.S# AND T3.C# = '003'
           
LEFT JOIN SC AS T4
                     
ON SC.S# = T4.S# AND T4.C# = '004'
     
WHERE student.S#=SC.S# and
     
ISNULL(T1.score,0) + ISNULL(T2.score,0) + ISNULL(T3.score,0) + ISNULL(T4.score,0)
     
NOT IN
      (
SELECT
           
DISTINCT
           
TOP 15 WITH TIES
           
ISNULL(T1.score,0) + ISNULL(T2.score,0) + ISNULL(T3.score,0) + ISNULL(T4.score,0)
     
FROM sc
           
LEFT JOIN sc AS T1
                     
ON sc.S# = T1.S# AND T1.C# = 'k1'
           
LEFT JOIN sc AS T2
                     
ON sc.S# = T2.S# AND T2.C# = 'k2'
           
LEFT JOIN sc AS T3
                     
ON sc.S# = T3.S# AND T3.C# = 'k3'
           
LEFT JOIN sc AS T4
                     
ON sc.S# = T4.S# AND T4.C# = 'k4'
     
ORDER BY ISNULL(T1.score,0) + ISNULL(T2.score,0) + ISNULL(T3.score,0) + ISNULL(T4.score,0) DESC);

23、统计列印各科成绩,各分数段人数:课程ID,课程名称,[100-85],[85-70],[70-60],[ <60]
   
SELECT SC.C# as
阅读(566) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~