本篇內(nèi)容介紹了“Java數(shù)據(jù)庫面試題有哪些”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
10年積累的成都網(wǎng)站建設(shè)、做網(wǎng)站經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有崇信免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
基本表結(jié)構(gòu):
student(sno,sname,sage,ssex)學(xué)生表
course(cno,cname,tno) 課程表
sc(sno,cno,score) 成績(jī)表
teacher(tno,tname) 教師表
101,查詢課程1的成績(jī)比課程2的成績(jī)高的所有學(xué)生的學(xué)號(hào)
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,查詢平均成績(jī)大于60分的同學(xué)的學(xué)號(hào)和平均成績(jī)
select a.sno as "學(xué)號(hào)", avg(a.score) as "平均成績(jī)"
from
(select sno,score from sc) a
group by sno having avg(a.score)>60
103,查詢所有同學(xué)的學(xué)號(hào)、姓名、選課數(shù)、總成績(jī)
select a.sno as 學(xué)號(hào), b.sname as 姓名,
count(a.cno) as 選課數(shù), sum(a.score) as 總成績(jī)
from sc a, student b
where a.sno = b.sno
group by a.sno, b.sname
或者:
selectstudent.sno as 學(xué)號(hào), student.sname as 姓名,
count(sc.cno) as 選課數(shù), sum(score) as 總成績(jī)
from student left Outer join sc on student.sno = sc.sno
group by student.sno, sname
104,查詢姓“張”的老師的個(gè)數(shù)
selectcount(distinct(tname)) from teacher where tname like '張%‘
或者:
select tname as "姓名", count(distinct(tname)) as "人數(shù)"
from teacher
where tname like'張%'
group by tname
105,查詢沒學(xué)過“張三”老師課的同學(xué)的學(xué)號(hào)、姓名
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,查詢同時(shí)學(xué)過課程1和課程2的同學(xué)的學(xué)號(hào)、姓名
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,查詢學(xué)過“李四”老師所教所有課程的所有同學(xué)的學(xué)號(hào)、姓名
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,查詢課程編號(hào)1的成績(jī)比課程編號(hào)2的成績(jī)高的所有同學(xué)的學(xué)號(hào)、姓名
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,查詢所有課程成績(jī)小于60分的同學(xué)的學(xué)號(hào)、姓名
select sno,sname from student
where sno not in (select distinct sno from sc where score > 60)
110,查詢至少有一門課程與學(xué)號(hào)為1的同學(xué)所學(xué)課程相同的同學(xué)的學(xué)號(hào)和姓名
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數(shù)據(jù)庫面試題有哪些”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
網(wǎng)站名稱:Java數(shù)據(jù)庫面試題有哪些
分享地址:http://jinyejixie.com/article36/gpshpg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、網(wǎng)站改版、企業(yè)網(wǎng)站制作、域名注冊(cè)、品牌網(wǎng)站建設(shè)、網(wǎng)站維護(hù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)