千家信息网

数据库相关面试题有哪些

发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,这篇文章主要介绍"数据库相关面试题有哪些",在日常操作中,相信很多人在数据库相关面试题有哪些问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"数据库相关面试题有哪些"的疑惑
千家信息网最后更新 2026年11月02日数据库相关面试题有哪些

这篇文章主要介绍"数据库相关面试题有哪些",在日常操作中,相信很多人在数据库相关面试题有哪些问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"数据库相关面试题有哪些"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

基本表结构:

student(sno,sname,sage,ssex)学生表
course(cno,cname,tno) 课程表
sc(sno,cno,score) 成绩表

teacher(tno,tname) 教师表

101,查询课程1的成绩比课程2的成绩高的所有学生的学号
select a.sno from
(select sno,score from sc where cno=1) a,
(select sno,score from sc where cno=2) b
where a.score>b.score and a.sno=b.sno

102,查询平均成绩大于60分的同学的学号和平均成绩
select a.sno as "学号", avg(a.score) as "平均成绩"
from
(select sno,score from sc) a
group by sno having avg(a.score)>60

103,查询所有同学的学号、姓名、选课数、总成绩
select a.sno as 学号, b.sname as 姓名,
count(a.cno) as 选课数, sum(a.score) as 总成绩
from sc a, student b
where a.sno = b.sno
group by a.sno, b.sname

或者:

selectstudent.sno as 学号, student.sname as 姓名,
count(sc.cno) as 选课数, sum(score) as 总成绩
from student left Outer join sc on student.sno = sc.sno
group by student.sno, sname


104,查询姓"张"的老师的个数

selectcount(distinct(tname)) from teacher where tname like '张%'
或者:
select tname as "姓名", count(distinct(tname)) as "人数"
from teacher
where tname like'张%'
group by tname

105,查询没学过"张三"老师课的同学的学号、姓名
select student.sno,student.sname from student
where sno not in (select distinct(sc.sno) from sc,course,teacher
where sc.cno=course.cno and teacher.tno=course.tno and teacher.tname='张三')

106,查询同时学过课程1和课程2的同学的学号、姓名
select sno, sname from student
where sno in (select sno from sc where sc.cno = 1)
and sno in (select sno from sc where sc.cno = 2)
或者:

selectc.sno, c.sname from
(select sno from sc where sc.cno = 1) a,
(select sno from sc where sc.cno = 2) b,
student c
where a.sno = b.sno and a.sno = c.sno
或者:

select student.sno,student.sname from student,sc where student.sno=sc.sno and sc.cno=1
and exists( select * from sc as sc_2 where sc_2.sno=sc.sno and sc_2.cno=2)

107,查询学过"李四"老师所教所有课程的所有同学的学号、姓名
select a.sno, a.sname from student a, sc b
where a.sno = b.sno and b.cno in
(select c.cno from course c, teacher d where c.tno = d.tno and d.tname = '李四')

或者:

select a.sno, a.sname from student a, sc b,
(select c.cno from course c, teacher d where c.tno = d.tno and d.tname = '李四') e
where a.sno = b.sno and b.cno = e.cno

108,查询课程编号1的成绩比课程编号2的成绩高的所有同学的学号、姓名
select a.sno, a.sname from student a,
(select sno, score from sc where cno = 1) b,
(select sno, score from sc where cno = 2) c
where b.score > c.score and b.sno = c.sno and a.sno = b.sno

109,查询所有课程成绩小于60分的同学的学号、姓名
select sno,sname from student
where sno not in (select distinct sno from sc where score > 60)

110,查询至少有一门课程与学号为1的同学所学课程相同的同学的学号和姓名
select distinct a.sno, a.sname
from student a, sc b
where a.sno <> 1 and a.sno=b.sno and
b.cno in (select cno from sc where sno = 1)

或者:

select s.sno,s.sname
from student s,
(select sc.sno
from sc
where sc.cno in (select sc1.cno from sc sc1 where sc1.sno=1)and sc.sno<>1
group by sc.sno)r1
where r1.sno=s.sno

到此,关于"数据库相关面试题有哪些"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!

学号 课程 姓名 查询 同学 成绩 数据 数据库 学习 总成 总成绩 老师 李四 学生 更多 张三 帮助 实用 相同 接下来 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 互联网新科技 重生之互联网科技帝国 互联网科技未来 科技制造互联网公司 金融科技与互联网金融 杭州互联网科技公司 互联网科技公司的市场部门 哈尔滨新华互联网科技学院 黑科技闪耀互联网之光 深圳市优智互联网科技有限公司 西安小鹰速贷互联网科技有限公司 上海科技产业互联网平台 每天都有哪些好的互联网科技 皮皮虾互联网科技有限公司 互联网科技资金流入 互联网科技快讯热点 互联网科技年终奖 卡尔迅互联网科技有限公司 下一代互联网重大应用科技园 恒生科技互联网指数十大成分股 新华互联网科技校企合作 阿里互联网科技公司 武汉健翔互联网络科技有限公司 坤平互联网科技 互联网行业科技股 宇信科技在杭州互联网排第几 版纳互联网科技选哪家 悟空问答互联网科技 黑龙江互联网科技公司 广东猫王互联网科技有限公司电话
0