没有合适的资源?快使用搜索试试~ 我知道了~
SQLSERVER查询练习习题.doc
0 下载量 169 浏览量
2022-12-02
23:23:55
上传
评论
收藏 56KB DOC 举报
温馨提示
试读
16页
SQLSERVER查询练习习题.doc
资源推荐
资源详情
资源评论
.
.
. .word..
设教学数据库 Education 有三个关系:
学生关系 s〔student_id,student_name,birthday,sex,major〕;
学习关系 sc〔student_id,course_id,score〕;
课程关系 course〔course_id,course_name,term,period,credit〕
查询问题:
单表查询
1:查所有年龄在 20 岁以下的学生 XX 及年龄。
select student_name,year(getdate()) - year(birthday) as 年龄
from s
where year(getdate()) - year(birthday) < 30
2:查考试成绩有不及格的学生的学号
select distinct student_id
from sc
where score < 60
3:查所年龄在 20 至 23 岁之间的学生 XX、系别及年龄。
select student_name,major,year(getdate()) - year(birthday)as 年龄
from s
where year(getdate()) - year(birthday) between 20 and 24
4:查舞蹈编导、英语、通信技术专业的学生 XX、性别。
select student_name, sex
from s
where major in ('舞蹈编导','英语','通信技术')
5:查不是舞蹈编导、英语、通信技术的学生 XX、性别
select student_name, sex
from s
.
.
. .word..
where major not in ('舞蹈编导','英语','通信技术')
6:查所有姓“〞的学生的 XX、学号和性别。
select student_name,student_id,sex
from s
where student_name like '%'
8:查所有不姓“〞且单名的学生的 XX。
select student_name
from s
where student_name not like '_'
9:查 C++课程的课程号。
select course_id
from course
where course_name='C++'
10:查缺考的学生的学号和课程号。
select student_id,course_id
from sc
where score is null
11:查开课学期为空值的课程编号和名称。
select course_id,course_name
from course
where term is null
12:查信息管理专业 20 岁以下的学生的学号和 XX。
.
.
. .word..
select student_id,student_name
from s
where major='信息管理' and year(getdate()) - year(birthday)<20
13:查舞蹈编导专业性别为女的学生 XX、性别。
select student_name,sex
from s
where major='舞蹈编导' and sex='女'
14:查询选修了 110010 课程的学生的学号和成绩,其结果按分数的降序排列。
select student_id,score
from sc
where course_id='110010'
order by score desc
15:查询全体学生的情况,查询结果按所在专业升序排列,对同一系中的学生按
年龄降序排列。
select *
from s
order by major asc,year(getdate()) - year(birthday) desc
16:查询学生总人数。
select count(*) as 人数
from s
17:查询选修了课程的学生人数。
select count(*) as 选修课程人数
剩余15页未读,继续阅读
资源评论
zzzzl333
- 粉丝: 674
- 资源: 7万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功