(1)查询性别为“男”的所有学生的名称并按学号升序排列。
select hsy_Sname,hsy_Sno
from Husy_Students
where hsy_Ssex='男'
order by hsy_Sno asc
(2)查询学生的选课成绩合格的课程成绩,并把成绩换算为积分。积分的计算公式为:[1+(考试成绩-60)*0.1]*Ccredit。考试成绩>=60 否则=0
SELECT hsy_Sno,hsy_Cno,hsy_Score,(hsy_Score-60)*0.1+1
FROM Husy_Reports
WHERE hsy_Score>=60
(3)查询学分是3或4的课程的名称。
select hsy_Cname
from Husy_Courses
where hsy_Scredit=3 or hsy_Scredit=4
(4)查询所有课程名称中含有“算法”的课程编号。
select hsy_Cno
from Husy_Courses
where hsy_Cname like '%算法%'
(5)查询所有选课记录的课程号(不重复显示)。
select distinct hsy_Cno
from Husy_Reports
(6)统计所有老师的平均工资。
select avg(hsy_Tsalary)
from Husy_Teachers
(7)查询所有教师的编号及选修其课程的学生的平均成绩,按平均成绩降序排列。
(8)统计各个课程的选课人数和平均成绩。
select hsy_Cno,count (hsy_Sno)人数,avg(hsy_Score)平均成绩
from Husy_Reports
group by hsy_Cno
(9)查询至少选修了三门课程的学生编号和姓名。
select hsy_Sno,hsy_Sname
from Husy_Students
where hsy_Sno in(
select hsy_Sno from Husy_Reports
group by hsy_Sno
having count(hsy_Cno)>=3 )
(10)查询编号S26的学生所选的全部课程的课程名和成绩。
select hsy_Cname,hsy_Score
from Husy_Reports,Husy_Courses
where hsy_Sno='S26' and Husy_Courses.hsy_Cno =Husy_Reports.hsy_Cno
(11)查询所有选了“数据库原理及其应用”课程的学生编号和姓名。
(12)求出选择了同一个课程的学生对。
(13)求出至少被两名学生选修的课程编号。
select hsy_Cno
from Husy_Reports
group by hsy_Cno
having count(hsy_Sno)>=2
(14)查询选修了编号S26的学生所选的某个课程的学生编号。
select distinct hsy_Sno
FROM Husy_Reports
where hsy_Cno in(
select hsy_Cno from Husy_Reports
where hsy_Sno='S26')
(15)查询学生的基本信息及选修课程编号和成绩。
select Husy_Students.hsy_Sno,hsy_Sname,hsy_Semail,hsy_Cno,hsy_Score
from Husy_Students,Husy_Reports
where Husy_Reports.hsy_Sno=Husy_Students.hsy_Sno
(16)查询学号S52的学生的姓名和选修的课程名称及成绩。
(17)查询和学号S52的学生同性别的所有学生资料。
(18)查询所有选课的学生的详细信息。
select * from Husy_Students
where hsy_Sno in(select distinct hsy_Sno from Husy_Reports)
(19)查询没有学生选的课程的编号和名称。
(20)查询选修了课程名为C++的学生学号和姓名。
select Husy_Students.hsy_Sno,hsy_Sname
from Husy_Students,Husy_Reports,Husy_Courses
where hsy_Cname='C++' and Husy_Reports.hsy_Cno=Husy_Courses.hsy_Cno
and Husy_Reports.hsy_Sno=Husy_Students.hsy_Sno
(21)找出选修课程UML或者课程C++的学生学号和姓名。
select hsy_Sno,hsy_Sname from Husy_Students
where hsy_Sno
in(select hsy_Sno from Husy_Reports
where hsy_Cno
in(select hsy_Cno from Husy_Courses
where hsy_Cname='C++' or hsy_Cname='UML')
)
(22)找出和课程UML或课程C++的学分一样课程名称。
select hsy_Cname
from Husy_Courses
where hsy_Scredit in
(select hsy_Scredit from Husy_Courses
where hsy_Cname='UML'or hsy_Cname='C++')
(23)查询所有选修编号C01的课程的学生的姓名。
select hsy_Sname
from Husy_Students
where hsy_Sno
in(select distinct hsy_Sno from Husy_Reports
where hsy_Cno='C01' )
(24)查询选修了所有课程的学生姓名。
(25)利用集合查询方式,查询选修课程C++或选择课程JAVA的学生的编号、姓名和积分。
select hsy_Sno,hsy_Sname,hsy_Scredit from Husy_Students
where hsy_Sno
in(select hsy_Sno from Husy_Reports
where hsy_Cno
in(select hsy_Cno from Husy_Courses
where hsy_Cname='C++' )
)
union
select hsy_Sno,hsy_Sname,hsy_Scredit from Husy_Students
where hsy_Sno in(select hsy_Sno from Husy_Reports
where hsy_Cno
in(select hsy_Cno from Husy_Courses
where hsy_Cname='UML' )
)
(26)实现集合交运算,查询既选修课程C++又选修课程JAVA的学生的编号、姓名和积分。
select hsy_Sno,hsy_Sname,hsy_Scredit from Husy_Students
where hsy_Sno
in(select hsy_Sno from Husy_Reports
where hsy_Cno
in(select hsy_Cno from Husy_Courses
where hsy_Cname='C++' )
)
Intersect
select hsy_Sno,hsy_Sname,hsy_Scredit from Husy_Students
where hsy_Sno in(select hsy_Sno from Husy_Reports
where hsy_Cno
in(select hsy_Cno from Husy_Courses
where hsy_Cname='UML' )
)
(27)实现集合减运算,查询选修课程C++而没有选修课程JAVA的学生的编号。
select hsy_Sno,hsy_Sname,hsy_Scredit from Husy_Students
where hsy_Sno
in(select hsy_Sno from Husy_Reports
where hsy_Cno
in(select hsy_Cno from Husy_Courses
where hsy_Cname='C++')
)
except
select hsy_Sno,hsy_Sname,hsy_Scredit from Husy_Students
where hsy_Sno in(select hsy_Sno from Husy_Reports
where hsy_Cno
in(select hsy_Cno from Husy_Courses
where hsy_Cname='JAVA' )
)