当前位置:文档之家› 数据库练习题

数据库练习题

1.查询所有学生的学号,姓名,性别,出生日期
select sno,sname,sex,birthday
from s
2.查询所有学生的年龄
select year(getdate())-year(birthday)as年龄
from s
3.查询成绩表中成绩在80~90范围的学生学号,课程号,成绩
select sno,cno,score
from sc
where score>=80 and score<=90
4.查询所有姓王和姓李的学生的信息的
select*
from s
where sname like'王%'or sname like'李%'
5.按成绩由大到小的顺序显示成绩表中所有的选课信息
select*
from sc
order by score desc
6.查询学生表中年龄最小的3位学生的信息。

select top 3*
from s
order by birthday desc
7.查询学生表中学生都来自于那些班级
8.统计学生表中男生的人数。

select count(sno)as人数
from s
where sex='男'
9.统计男生的平均年龄。

select avg(year(getdate())-year(birthday))as年龄
from s
where sex='男'
10.查询与“黄鹏”性别相同的学生的姓名,班级
select sname,class
from s
where sex in(select sex from s where sname='黄鹏')
11.统计各班人数,显示班级名称,班级人数
select class,count(*)as班级人数
from s
group by class
12.查询人数大于2的班级名称,班级人数
select class,count(*)as班级人数
from s
group by class
having count(*)>2
13.查询选修了c003号课程且成绩在85分以上的学生的姓名和成绩select sname,score
from s,sc
where cno='c003'and score>85
14.查询与学号为“1003”的同学在同班的学生信息。

select*
from s
where class=(select class from s where sno='1003')
15.查询学生表中年龄最小的学生的信息。

select*
from s
where birthday=(select min(birthday)from s )。

相关主题