SQLServer数据库应用与开发:第七章上机

代码及解释

7.1

use teaching
select teacherno,tname,major
from teacher
where prof='教授'

7.2

use teaching
select student.studentno as '学号',sname as '姓名',cname as '课程名称',final*0.9+daily*0.1 as '总评成绩'
into finalscore
from score,course,student
where student.studentno=score.studentno and score.courseno=course.courseno

select *
from finalscore

7.3

select sname as '学生姓名',count(*) as '大于75分的课程门数'
from score,student
where final>75 and score.studentno=student.studentno
group by score.studentno,student.sname

7.4

select *
from student
where sex='男' and (year(GETDATE())-year(birthdate)>(
select AVG(DATEDIFF(year,birthdate,getdate()))
from student
where sex='女'
))

7.5

select student.sname as '姓名',sum(period)/16 as '学分'
from course,student,score
where student.studentno=score.studentno and course.courseno=score.courseno and final>60
group by score.studentno,student.sname

解释:
1.关于学分如何计算看P143

7.7

select student.studentno as '学号',student.sname as '姓名',course.cname as '课程名称',sum(period)/16 as '学分'
from course,student,score
where student.studentno=score.studentno and course.courseno=score.courseno and final>60 AND SUBSTRING(student.studentno,1,2)='18'
group by student.studentno,student.sname,course.cname

7.8

select student.studentno,sname,phone,email
from student
where studentno in(
select distinct studentno
from score
where final<60
union
select studentno
from score
group by studentno 
having count(courseno)<3
)

解释:
1.union两个结果求并集

猜你喜欢

转载自blog.csdn.net/m0_53438035/article/details/124653429