数据库作业
第一部分
1.查询所有学生情况.
select
fromstudent
2.查询所有学生的姓名,性别以及年龄。
selectsname,ssex,sage
fromdbo.Student
3.查询所有学生10年后的年龄。
selectsname姓名,sage年龄,sage+10十年后
fromdbo.Student
4.查询所有课程(列名用中文显示)。
selectcname课程名,Cpno课程号,Ccredit学分
fromdbo.course
5.查看究竟有哪些学生选课(重复学号显示一次)。
selectdistinctsno
fromdbo.sc
6.查看究竟有哪些课程被选择了(重复课程号显示一次)。
selectdistinctcno,cname
fromdbo.course
7.查询计算机系的所有学生的姓名和年龄。
selectsname,sage
fromdbo.Student
wheresdept=''计算机''
8.查询体育课的学分。
selectCcredit
fromdbo.course
wherecname=''体育''
9.查询年龄小于18的学生。
selectsname,sage
fromdbo.Student
wheresage<18
10.查询年龄大于20的学生。
selectsname,sage
fromdbo.Student
wheresage>20
11.查询年龄介于18和20之间的学生(包括18和20)。
selectsname,sage
fromdbo.Student
wheresagebetween18and20
12.查询年龄不在18和20之间的学生。
selectsname,sage
fromdbo.Student
wheresagenotbetween18and20
13.查询年龄为18,20,22的学生。
selectsname
fromdbo.Student
wheresagein(''18'',''20'',''22'')
14.查询年龄不是18,20,22的学生。
selectsname
fromdbo.Student
wheresagenotin(''18'',''20'',''22'')
15.查询所有姓张的学生。
selectsname
fromdbo.Student
wheresnamelike''张%''
16.查询姓张,王,周的同学姓名,学号及性别。
selectsname,sno,ssex
fromdbo.Student
wheresnamelike''张%''orsnamelike''王%''orsnamelike''周%''
17.查询所有没有先行课的课程。
selectcno
fromdbo.course
whereCpnoisnull
18.查询有先行课的课程。
selectcno
fromdbo.course
whereCpnoisnotnull
19.在计算机系中找姓张的或者姓李的男生并且按照年龄从大到小排序。
select
fromdbo.Student
wheresdept=''计算机''andssex=''男''and(snamelike''张%''orsnamelike''李%'')
orderbysage
20.查询所有学生信息,显示结果先按系从大到小排序,再按年龄排序。
select
fromdbo.Student
orderbysdept,sagedesc
第二部分
1.查询所有课程的平均分,最高分,最低分和总分数。
selectavg(grade)as''平均分''max(grade)as''最高分''min(grade)as''最低分''sum(grade)as''总分数''
fromdbo.sc
2.查询有多少个学生参加选课。
selectcount(distinctsno)as''学生数''
fromdbo.sc
3.查询计算机系有多少人过岁。
selectcount()
fromdbo.Student
wheresdept=''计算机''andsage>20
4.统计计算机系的男生多少人。
selectcount()as''男生总数''
fromdbo.Student
wheresdept=''计算机''andssex=''男''
5.查询每门课(课程号)的最高分和最分。
selectcno,max(grade)as''最高分'',min(grade)as''最低分''
fromdbo.sc
groupbycno
6.查询计算机系中男生多少人,女生多少人。
selectssex性别,count()as''人数''
fromdbo.Student
wheresdept=''计算机''
groupbyssex
7.查询每个选课学生的平均分。
selectsno学号,avg(grade)as''平均分''
fromdbo.sc
groupbysno
|
|