中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Java面試中出現率極高的數據庫查詢題有哪些

發布時間:2020-12-02 10:54:34 來源:億速云 閱讀:189 作者:小新 欄目:MySQL數據庫

這篇文章將為大家詳細講解有關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 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

關于Java面試中出現率極高的數據庫查詢題有哪些就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

龙南县| 年辖:市辖区| 铁岭县| 游戏| 赤城县| 垣曲县| 枣阳市| 郴州市| 黄平县| 黄陵县| 安国市| 临夏县| 佳木斯市| 比如县| 淮安市| 三原县| 崇阳县| 东丰县| 耒阳市| 铜川市| 保德县| 宜黄县| 康定县| 惠来县| 义马市| 潮安县| 巴东县| 余姚市| 诏安县| 赣州市| 南通市| 论坛| 福贡县| 越西县| 隆尧县| 贡嘎县| 商城县| 大兴区| 色达县| 灵丘县| 资阳市|