java高频率基础面试题——(九)

互联网 20-9-14

想要成为一名合格的Java后端开发者,数据库知识必不可少,对数据库的掌握熟悉度的考察也是对这个人是否有扎实基本功的考察。

(更多相关面试题推荐:java面试题及答案)

特别对于初级开发者,面试可能不会去问框架相关知识,但是绝对不会不去考察数据库知识,这里收集一些常见类型的SQL语句,无论对于平常开发还是准备面试,都会有助益。

基本表结构:

 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
select a.sno as "学号", avg(a.score) as "平均成绩"  from (select sno,score from sc) a  group by sno having avg(a.score)>60
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
selectcount(distinct(tname)) from teacher where tname like '张%‘
select tname as "姓名", count(distinct(tname)) as "人数"  from teacher  where tname like'张%' group by tname
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='张三')

(推荐学习:java课程)

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)
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
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
select sno,sname from student where sno not in (select distinct sno from sc where score > 60)
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

相关推荐:java入门教程

以上就是java高频率基础面试题——(九)的详细内容,更多内容请关注技术你好其它相关文章!

来源链接:
免责声明:
1.资讯内容不构成投资建议,投资者应独立决策并自行承担风险
2.本文版权归属原作所有,仅代表作者本人观点,不代表本站的观点或立场
标签: 面试题
上一篇:php获取远程图片并下载保存到本地的方法分析 下一篇:java中判断数组是否为空的方法

相关资讯