Java面试中出现率极高的数据库查询题有哪些
发表于:2026-11-03 作者:千家信息网编辑
千家信息网最后更新 2026年11月03日,这篇文章将为大家详细讲解有关Java面试中出现率极高的数据库查询题有哪些,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。基本表结构:teacher(tno,tname
千家信息网最后更新 2026年11月03日Java面试中出现率极高的数据库查询题有哪些
这篇文章将为大家详细讲解有关Java面试中出现率极高的数据库查询题有哪些,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
基本表结构:
teacher(tno,tname) 教师表
student(sno,sname,sage,ssex)学生表
course(cno,cname,tno) 课程表
sc(sno,cno,score) 成绩表
NO.1查询课程1的成绩比课程2的成绩高的所有学生的学号
select a.sno from(select sno,score from sc where cno=1) a,(select sno,score from sc where cno=2) bwhere a.score>b.score and a.sno=b.sno
NO.2查询平均成绩大于60分的同学的学号和平均成绩
select a.sno as "学号", avg(a.score) as "平均成绩" from(select sno,score from sc) a group by sno having avg(a.score)>60
NO.2查询所有同学的学号、姓名、选课数、总成绩
select a.sno as 学号, b.sname as 姓名,count(a.cno) as 选课数, sum(a.score) as 总成绩from sc a, student bwhere a.sno = b.snogroup 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.snogroup by student.sno, sname
NO.3查询姓"张"的老师的个数
selectcount(distinct(tname)) from teacher where tname like '张%'
或者:
select tname as "姓名", count(distinct(tname)) as "人数" from teacher where tname like'张%'group by tname
NO.4查询没学过"张三"老师课的同学的学号、姓名
select student.sno,student.sname from studentwhere sno not in (select distinct(sc.sno) from sc,course,teacherwhere sc.cno=course.cno and teacher.tno=course.tno and teacher.tname='张三')
NO.5查询同时学过课程1和课程2的同学的学号、姓名
select sno, sname from studentwhere 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 cwhere 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=1and exists( select * from sc as sc_2 where sc_2.sno=sc.sno and sc_2.cno=2)
NO.6查询学过"李四"老师所教所有课程的所有同学的学号、姓名
select a.sno, a.sname from student a, sc bwhere 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 = '李四') ewhere a.sno = b.sno and b.cno = e.cno
NO.7查询课程编号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
NO.8查询所有课程成绩小于60分的同学的学号、姓名
select sno,sname from studentwhere sno not in (select distinct sno from sc where score > 60)
NO.9查询至少有一门课程与学号为1的同学所学课程相同的同学的学号和姓名
select distinct a.sno, a.snamefrom student a, sc bwhere a.sno <> 1 and a.sno=b.sno andb.cno in (select cno from sc where sno = 1)
或者:
select s.sno,s.sname from student s,(select sc.sno from scwhere sc.cno in (select sc1.cno from sc sc1 where sc1.sno=1)and sc.sno<>1group by sc.sno)r1where r1.sno=s.sno
关于Java面试中出现率极高的数据库查询题有哪些就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
学号
查询
课程
姓名
同学
成绩
总成
总成绩
老师
李四
数据
数据库
学生
更多
篇文章
张三
不错
实用
相同
个数
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
中智农互联网科技
涨乐互联网科技
互联网巨头反垄断金融科技
互联网与科技金融数据
互联网科技未来
朗涯互联网科技
未来的互联网科技
北京禾田雨橡互联网科技
互联网高科技企业
互联网前沿科技
互联网实体化科技化
玖二柒互联网科技公司待遇
济南华为互联网科技产业总部基地
重庆威客帮互联网科技
福建科技产业互联网发展
速维有品互联网信息科技(苏州)有限公司
宇信科技在杭州互联网排第几
万物互联网智能科技
好易买互联网科技
广州全民伙伴互联网科技有限公司
互联网金融 科技金融
紫鲸互联网科技
壹账通互联网科技
碳银互联网科技有限公司
开启互联网科技时代小说
江苏南京365互联网科技
宁波青枫互联网科技有限公司
洛阳昕诺飞互联网科技有限公司
乌鲁木齐新华智原互联网科技学校
湖北辰鑫科技互联网