SQL实验2.docVIP

  • 548
  • 0
  • 约2.68万字
  • 约 65页
  • 2017-05-12 发布于河南
  • 举报
SQL实验2

SQL实验2 利用查询分析器完成实验 School数据库中存在以下四张表: 表STUDENTS( sid,sname,email,grade) 表TEACHERS(tid,tname,email,salary) 表COURSES(cid,cname,hour) 表CHOICES(no,sid,cid,tid,score) 学生选择课程,一个课程对应一个老师,表CHOICES保存学生的选课记录,对数据库进行以下操作: 查询年级为2001的所有学生的名字,并按标号顺序排列。 select sname from STUDENTS where grade=2001 ORDER BY sid ASC 查询学生的选修课成绩合格的课程成绩,并把成绩换算成积分,60分对应积分1,每增加1分,积分增加0.1 select cid, score, 1+0.1*(score-60) jifen from CHOICES Where score=60; 查询学时是48或64的课程名称 select cname from COURSES where hour=48 OR hour=64 查询所有课程名称中含有data 的课程编号 select cid from COURSES where cname LIKE %data% 查询所有选课记录的课程号(不重复显示) select distinct cid from CHOICES 统计所有老师的平均工资 select AVG(salary) from TEACHERS 查询所有老师的编号及选修其课程的学生的平均成绩,按平均成绩降序排列 select tid , AVG(score) from CHOICES GROUP BY tid , cid ORDER BY AVG(score) DESC; 统计每个课程的选课人数和平均成绩 select cid , count(distinct sid), AVG(score) from CHOICES GROUP BY cid; 查询至少选修了三门课程的学生编号 select sid from CHOICES GROUP BY sid having count(cid)=3; 查询编号为800009026的学生姓名、所选的全部课程的课程名和成绩(3行) select distinct sname,cname , score from STUDENTS,COURSES, CHOICES where STUDENTS.sid = 800009026 and STUDENTS.sid = CHOICES.sid and COURSES.cid=CHOICES.cid ; 查询所有选修了database的学生 select sid from COURSES , CHOICES where COURSES.cid = CHOICES.cid and cname = database; 求出选择了同一门课程的学生对 查询至少被两名学生选修了的课程编号 select cid from CHOICES GROUP BY cid having count(distinct sid)=2; 查询选修了编号800009026的学生所选的某个课程的学生编号 select distinct sid from CHOICES where cid in (select cid from CHOICES where sid=800009026) and sid800009026; 查询学生的基本信息及选修课程编号和成绩 select STUDENTS.sid , sname , email , grade , cid , score from STUDENTS,CHOICES where STUDENTS.sid =CHOICES.sid; 查询学号800009026的学生的姓名和选修的课程的名称及成绩(3 行受影响) select sname, cname, score from STUDENTS,COURSES,CHOICES where CHOICES.sid=800009026 and CHOICES.sid=STUDENTS.sid and COURSES.cid=CHOICES.cid; 查询与学号850955252的学生同年级的所有学生资料 select * from STUDENTS where grade=(select grade from STUDENTS where sid=850955252 );

文档评论(0)

1亿VIP精品文档

相关文档