查询计算机专业及选修了英语的学生,实验五 数据库综合查询(学生)
實驗五 數據庫綜合查詢
一、實驗目的
1. 掌握SELECT語句的基本語法和查詢條件表示方法; 2. 掌握查詢條件種類和表示方法; 3. 掌握連接查詢的表示及使用; 4. 掌握嵌套查詢的表示及使用; 5. 了解集合查詢的表示及使用。
二、實驗內容
1. 了解SELECT語句的基本語法格式和執行方法;
2. 以數據庫原理實驗5數據為基礎,請使用T-SQL 語句實現進行相應操作; 3. 完成實驗報告。
三、實驗步驟
1. 查詢以‘數據_’開頭,且倒數第3個字符為‘結’的課程的詳細情況 select*
from course
where Cname like '數據\\_%結_'escape'\\'
2. 查詢名字中第2個字為‘陽’的學生姓名和學號及選修的課程號、課程名; select sname 姓名,student.sno 學號,course.cno 課程號,course.cname 課程名
from student,course,sc
where student.sno=sc.sno and sc.cno=course.cno and sname like'_陽%'
3. 列出選修了‘數學’或者‘大學英語’的學生學號、姓名、所在院系、選修
課程號及成績;
select student.sno,sname,sdept,cno,grade
from student,sc
where student.sno=sc.sno and cno IN(select cno from course where cname='數學'OR CNAME='大學英語')
4. 查詢缺少成績的所有學生的詳細情況;
select*
from student
where not exists(select* from sc
where sno=student.sno and grade is not null) select* from student where sno in( select sno from sc
where grade is null)
5. 查詢與‘張力’(假設姓名唯一)年齡不同的所有學生的信息; select b.*
from student a,student b
where a.sname='張力'and a.sage<>b.sage
6. 查詢所選課程的平均成績大于張力的平均成績的學生學號、姓名及平均成
績;
select student.sno,sname,平均成績=avg(grade)
from student,sc
where sc.sno=student.sno group by student.sno,sname having avg(grade)>( select avg(grade) from sc where sno=( select sno from student where sname='張力'))
7. 按照?學號,姓名,所在院系,已修學分?的順序列出學生學分的獲得情況。
其中已修學分為考試已經及格的課程學分之和;
select student.sno 學號,sname 姓名,sdept 院系,已修學分=sum(credit)
from student,course,sc
where student.sno=sc.sno and course.cno=sc.cno and grade>=60 group by student.sno,sname,sdept
8. 列出只選修一門課程的學生的學號、姓名、院系及成績; select student.sno 學號,sname 姓名,sdept 院系,grade
from student,sc
where student.sno=sc.sno and sc.sno in( select sno from sc group by sno
having count(cno)=1)
9. 查找選修了至少一門和張力選修課程一樣的學生的學號、姓名及課程號; select distinct student.*
from student where sno in( select sno from sc
where cno in( select cno from course
where cname='數據庫'or cname='數據結構'))
10. 只選修?數據庫?和?數據結構?兩門課程的學生的基本信息; select z.cno,z.cname,x.sno,x.sname,grade
from student x,sc y,course z where x.sno=y.sno and y.cno=z.cno
11. 至少選修?數據庫?或?數據結構?課程的學生的基本信息;
select *
from student,sc,course where student.sno=sc.sno and sc.cno=course.cno and cname='數據庫'or
cname='數據結構'
12. 列出所有課程被選修的詳細情況,包括課程號、課程名、學號、姓名及成績; select course.cno,course.cname,student.sno,student.sname,grade
from student,sc,course where student.sno=sc.cno
and sc.cno=course.cno
13. 查詢只被一名學生選修的課程的課程號、課程名; select cno,cname
from course where cno in (select cno
from sc group by cno
having count(sno)=1)
14. 使用嵌套查詢列出選修了?數據結構?課程的學生學號和姓名; select sno,sname
from student where sno in (select sno from sc where cno in (select cno from course
where cname='數據結構'))
15. 使用嵌套查詢查詢其它系中年齡小于CS系的某個學生的學生姓名、年齡和
院系;
select sname,sage,sdept
from student where sage< (select max(sage) from student where sdept='cs'
and sdept<>'cs')
16. 使用ANY、ALL 查詢,列出其他院系中比CS系所有學生年齡小的學生; select sname,sage
from student where sageand sdept<>'cs')
select sname,sage from student where sageand sdept<>'cs')
17. 分別使用連接查詢和嵌套查詢,列出與‘張力’在一個院系的學生的信息; select*
from student
where sdept= (select sdept from student
where sname='張力')
18. 使用集合查詢列出CS系的學生以及性別為女的學生名單; select sname
from student where sdept='cs' union
select sname from student
where ssex='女'
19. 使用集合查詢列出CS系的學生與年齡不大于19歲的學生的交集、差集; select*
from student where sdept='cs' intersect select* from student
where sage<=19
20. 使用集合查詢列出選修課程1的學生集合與選修課程2的學生集合的交集; select sno
from sc where cno='1' intersect select sno from sc
where cno='2'
總結
以上是生活随笔為你收集整理的查询计算机专业及选修了英语的学生,实验五 数据库综合查询(学生)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 三星上网本官网(三星登录官网)
- 下一篇: 4g的服务器mysql配置文件,服务器物