数据库SQLsever语句练习数据库原理.docx
- 文档编号:8022287
- 上传时间:2023-01-28
- 格式:DOCX
- 页数:11
- 大小:597.04KB
数据库SQLsever语句练习数据库原理.docx
《数据库SQLsever语句练习数据库原理.docx》由会员分享,可在线阅读,更多相关《数据库SQLsever语句练习数据库原理.docx(11页珍藏版)》请在冰豆网上搜索。
数据库SQLsever语句练习数据库原理
建表:
Student:
Course:
SC:
1.找出CS系中的所有女生
语句:
select*fromStudent
whereSsex='女'andSdept='CS';
2.找出所有考试不及格的学生学号
语句:
selectSnofromSC
whereGrade<60;
3.查找所有姓刘的学生的学号、姓名、系科、性别
语句:
selectSno,Sname,Ssex,Sdept
fromStudent
whereSnamelike'刘%';
4.以性别和年龄的降序查询出学生表中的全部记录
语句:
select*fromStudent
orderbySsex,SageDESC;
5.找出IS系中所有小于20岁的学生和MA系中所有的男生的基本信息
语句:
Select*fromStudent
where(Sdept='IS'andSage<20)or(Sdept='MA'andSsex='男');
6.按照课程进行汇总,输出课程号、平均分和选修人数
语句:
selectCno,AVG(Grade)平均分,COUNT(Student.Sno)人数
fromStudent,SC
whereStudent.Sno=SC.Sno
groupbySC.Cno;
7.查找选修了课程的学生的姓名、学号、系科
语句:
selectdistinctStudent.sno学号,Sname,Sdept
fromStudent,SC
whereStudent.Sno=SC.Sno;
8.查找有学生选修的课程的课程名和学分
语句:
selectdistinctCname,Ccredit
fromStudent,SC,Course
whereStudent.Sno=SC.SnoandSc.Cno=Course.Cno;
9.查找没有选修课程的学生姓名、学号、系科
语句:
selectStudent.sno学号,Sname,Sdept
fromStudent
whereSnonotin
(
selectdistinctStudent.sno
fromStudent,SC
whereStudent.Sno=SC.Sno
);
10.查找课程1的选修情况,要求显示选修学生的姓名、学号、成绩、系科、性别
语句:
selectSname,Student.Sno,Ssex,Sdept,grade
fromStudent,SC,Course
wherestudent.Sno=SC.SnoandSC.Cno=Course.CnoandSo='1';
11.查找每门课程的后续课程名称、学分
语句:
selectame,ame,b.Ccredit
fromCoursealeftjoinCoursebona.cpno=o
12.查找每位学生的总学分
语句:
selectSno学号,sum(Ccredit)总学分
fromCourse,SC
whereCourse.Cno=SC.Cno
groupbySno
13.查询至少有2名男生的系科名称
语句:
selectSdept
fromStudent
whereSsex='男'
groupbySdept
havingcount(*)>=2;
14.查询成绩比该课程平均成绩低的同学的成绩表
语句:
selectSno,cno,Grade
fromSCx
whereGrade<(selectAVG(Grade)m
fromSCy
wherey.Cno=x.Cno);
15.查找所有平均分高于80的学生的学号、姓名、性别、系科
语句:
selectStudent.sno,sname,ssex,sdept
fromstudent
wherestudent.snoin
(
selectdistinctsno
fromscx
where
(
selectAVG(Grade)
fromSCy
wherey.Sno=x.Sno
)>80
);
16.统计平均分在60~70的学生人数
语句:
selectcount(*)人数
fromstudent
wherestudent.snoin
(
selectdistinctsno
fromscx
where(selectAVG(Grade)
fromSCywherey.Sno=x.Sno
)
between60and70);
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据库 SQLsever 语句 练习 原理