实验五 ACCESS应用 实验要求: 1.创建一个名为“学生管理”的数据库。 2.创建一个“学生档案”数据表

实验五 ACCESS应用 实验要求: 1.创建一个名为“学生管理”的数据库。 2.创建一个“学生档案”数据表,第1张

在access里面用罗斯文数据库实例建立个或自己建一个:

1、启动ACCESS建空数据库,取名“学生管理”。

2、建一个表,如果有excel数据可直接导入或在设计视图里面建表,字段名:学号、姓名、性别、出生日期(在里面限定》1988-1-1')、家庭住址。取名“学生档案”至于记录,自己输入几个人的情况。

3、建一个表取名“学生成绩”,字段名:学号、课程A、课程B、课程C、课程D、课程E。至于记录,自己输入几个人的情况。

4、,5、建关联的查询。在查询设计视图中将“学生档案”的学号拖到“学生成绩”的学号字段上。sql语句为:SELECT 学生档案.学号, 学生档案.姓名, [学生成绩]![课程A]+[学生成绩]![课程B] AS 总成绩 FROM 学生档案 INNER JOIN 学号 ON 学生档案.学号 = 学生成绩.学号,可以查询学生成绩。

6、sql语句为:SELECT 学生档案.学号, 学生档案.姓名, [学生成绩]![课程A],[学生成绩]![课程B] FROM 学生档案 where ((year(now)-year(出生日期)>20 INNER JOIN 学号 ON 学生档案.学号 = 学生成绩.学号

7、用以更新查询即可。

8、建一窗体(设计视图)里面建一些说明标签,一些功能按钮:按钮的单击事件调用相应的宏事件(或用VBA代码)调用需要的查询,取名“主窗体”。

一个简单的数据库就建好了。access功能很多,一句两句说不清楚,找本教材看看。

启动access建一空数据库,取名“学生管理”,在表对象中建一表(可用表设计视图,也可字节导入EXCEL数据表)取名“学生档案”,表的字段根据你需要而定,一般有序号、姓名、性别、班级、出生日期、家庭住址等等。

--查询全体学生的学号和姓名.

select Sno,Sname from Student

--查询全体学生的详细记录.

select * from Student

--查询所有选修课程的学生学号.

select distinct Sno from SC

--查询考试有不及格的学生学号.

select distinct Sno from SC where Grade<60

--查询不是信息系(is)、计算机系(cs)的学生性别、年龄、系别。

select Ssex,Sage,Sdept from Student where Sdept not in('is','cs')

--查询选修了4号课的学生学号和成绩,结果按成绩降序排列.

select Student.Sno,Grade from Student,SC where Cno='004' order by Grade desc

--查询每个课程号和相应的选课人数.

select Cno,count(Sno)选课人数 from SC group by Cno

--查询计算机系(cs)的学生姓名、年龄、系别。

select Sno,Sage,Sdept from Student where Sdept in('cs')

--查询年龄18~20岁的学生学号、姓名、系别、年龄。

select Sno,Sname,Sdept,Sage from Student where Sage between 18 and 20

--查询姓刘的学生的情况.

select * from Student where Sname like '刘%'

--查询既选修1号课程,又选修2号课程的学生学号.

select Sno from SC where Cno='001' and Cno='002'

select sno from SC where Cno='001' and Sno in (select Sno from SC where Cno='002')

select sno from SC where Cno='001' intersect select Sno from SC where Cno='002'

--查询学生的姓名和出生年份(今年2008年)

select Sname,2008-Sage as 出生年份 from student

--查询没有成绩的学生学号和课程号。

select Sno,Cno from sc where grade is null

--查询总成绩大于200分的学生学号。

select Sno from sc group by sno having sum(grade)>200

--查询每门课程不及格学生人数。

select cno,count(sno) 不及格人数 from sc where grade<60 group by cno

--查询不及格课程超过3门的学生学号。

select Sno from sc where grade<60 group by sno having count(grade)>3

--查询年龄为10~19岁的学生信息。

select * from student where Sage between 10 and 19

--查询全体学生情况,按所在系升序排列,同一个系的学生按年龄降序排列。

select * from student order by sdept, sage desc

--查询选了1号课程的学生平均成绩。

select avg(grade) from sc where cno='001'

--查询选了3号课程的学生的最高分。

select max(grade) from sc where cno='003'

--查询每个同学的总成绩。

select sno,sum(grade) 总成绩 from sc group by sno

---实验五

--查询每个学生及其选课情况。

select student.*,sc.*,course.* from student,sc,course where student.sno=sc.sno and sc.cno=course.cno

--select * from sc,student,course

--查询每门课程的间接选修课。

select first.cno,second.cpno from course first,course second where first.cpno=second.cno

--将STUDENT,SC进行右连接。

select * from student,sc

select student.*,sc.* from student right join sc on student.sno=sc.sno

--查询有不及格学生的姓名和所在系。

select Sname,Sdept from student,sc where grade<60 and student.sno=sc.sno

--查询所有成绩为优秀(大于90)的学生姓名。

select Sname from student where sno in (select sno from sc group by sno having min(grade)>90)and sno not in (select sno from sc where grade is null) --错误

select sname from student,sc where student.sno=sc.sno and student.sno not in(select sno from sc where grade is null) group by sname having min(grade)>=90

--查询既选修了2号课程又选修了3号课程的学生姓名、学号。

select distinct Sname,Sc.Sno from student,sc where student.sno=sc.sno and sc.sno in(select sno from sc where cno='002' and sno in (select sno from sc where cno='003'))

--查询和刘晨同一年龄的学生。

select Sno,sname from student where sage=(select sage from student where sname='刘晨')

--选修了课程名为“数据库”的学生姓名和年龄。

select Sname,Sage from student where sno in(select sno from sc where cno=(select cno from course where cname='数据库'))

--查询其他系比IS系任一学生年龄小的学生名单。

select sname from student where sdept!='is'and sage<(select max(sage) from student where sdept='is')

--查询其他系中比IS系所有学生年龄都小的学生名单。

select Sname from student where sdept!='is' and sage<(select min(sage) from student where sdept='is')

--查询选修了全部课程的学生姓名.

select sname from student where not exists(select * from course where not exists(select * from sc where sno=student.sno and cno=course.cno)) --正确

--查询计算机系学生及其性别是男的学生.

select * from student where sdept='is' or ssex='男'

--查询选修课程1的学生集合和选修2号课程学生集合的差集。

select sc.sno from student,sc where student.sno=sc.sno and cno='001'

except

select sc.sno from student,sc where student.sno=sc.sno and cno='002'

--或者

select sno from sc where cno='001' and sno not in (select sno from sc where cno='002')

--查询李丽同学不学的课程的课程号.

select distinct cno from sc where cno not in (select cno from student,sc where sname='李丽'and student.sno=sc.sno)

--查询选修了3号课程的学生平均年龄.

select avg(sage) from student where sno in(select sno from sc where cno='003')

--求每门课程学生的平均成绩.

select cno,avg(grade) from sc group by cno

--统计每门课程的学生选修人数(超过3人的人统计)。要求输出课程号和选修人数,结果按人数降序排列,若人数相同,按课程号升序排列。

--查询学号比刘晨大,而年龄比他小的学生姓名。

select sname from student where sno>(select sno from student where sname='刘晨')and sage<(select sage from student where sname='刘晨')

--求年龄大于女同学平均年龄的男同学的姓名和年龄。

select sname,sage from student where sage>(select avg(sage) from student where ssex='女')and ssex='男'

--求年龄大于所有女同学年龄的男同学姓名和年龄。

select sname,sage from student where sage>(select max(sage) from student where ssex='女')and ssex='男'

--查询至少选修了08002选修的全部课程的学生号码。

--select cno from sc where sno='08002'

--select sno from sc where cno IN (select cno from sc where sno='08002')

--select * from sc A,sc B where A.SNO=B.SNO

--select * from (select distinct* from sc A,sc B where A.SNO=B.SNO)as e

select distinct sno from sc sc1 where not exists (select * from sc sc2 where sc2.sno='08002' and not exists (select * from sc sc3 where sc3.sno=sc1.sno and sc3.cno=sc2.cno))

--查询08001和08002两个学生都选修的课程的信息。

select course.* from course,sc where sno='08001' and course.cno=sc.cno intersect select course.* from course,sc where sno='08002' and course.cno=sc.cno

--查询跟'08001'同学同姓的学生信息

select * from student where sname like(select left(sname,1) from student where sno='08001')+'%'


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/6462391.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-03-22
下一篇2023-03-22

发表评论

登录后才能评论

评论列表(0条)

    保存