旗下导航:搜·么
当前位置:网站首页 > MySQL教程 > 正文

Java口试中涌现率极高的数据库查询题【MySQL教程】,mysql,java

作者:搜教程发布时间:2019-12-01分类:MySQL教程浏览:31评论:0


导读:经历过口试的程序员都晓得,口试过程当中口试官能够对你问出光怪陆离的问题,但万变不离其宗,终归也是要问道重点上来,比方像是某一事情的基础操纵步骤以及代码的怎样编写等等,本文讲的就是最...
经历过口试的程序员都晓得,口试过程当中口试官能够对你问出光怪陆离的问题,但万变不离其宗,终归也是要问道重点上来,比方像是某一事情的基础操纵步骤以及代码的怎样编写等等,本文讲的就是最最典范的数据库查询问题。

基础表构造:

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 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='张三')

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

以上就是口试数据库相干事情灰常有能够碰到的问题,赶忙珍藏起来,好好看看吧!

【引荐课程:MYSQL进修视频】

以上就是Java口试中涌现率极高的数据库查询题的细致内容,更多请关注ki4网别的相干文章!

标签:mysqljava


欢迎 发表评论: