您好,登錄后才能下訂單哦!
本篇內容介紹了“java中數據庫的面試題有哪些”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
基本表結構:
student(sno,sname,sage,ssex)學生表
course(cno,cname,tno) 課程表
sc(sno,cno,score) 成績表
teacher(tno,tname) 教師表
111、把“sc”表中“王五”所教課的成績都更改為此課程的平均成績
update sc set score = (select avg(sc_2.score) from sc sc_2 wheresc_2.cno=sc.cno)
from course,teacher where course.cno=sc.cno and course.tno=teacher.tno andteacher.tname='王五'
112、查詢和編號為2的同學學習的課程完全相同的其他同學學號和姓名
這一題分兩步查:
1,
select sno
from sc
where sno <> 2
group by sno
having sum(cno) = (select sum(cno) from sc where sno = 2)
2,
select b.sno, b.sname
from sc a, student b
where b.sno <> 2 and a.sno = b.sno
group by b.sno, b.sname
having sum(cno) = (select sum(cno) from sc where sno = 2)
113、刪除學習“王五”老師課的sc表記錄
delete sc from course, teacher
where course.cno = sc.cno and course.tno = teacher.tno and tname = '王五'
114、向sc表中插入一些記錄,這些記錄要求符合以下條件:
將沒有課程3成績同學的該成績補齊, 其成績取所有學生的課程2的平均成績
insert sc select sno, 3, (select avg(score) from sc where cno = 2)
from student
where sno not in (select sno from sc where cno = 3)
115、按平平均分從高到低顯示所有學生的如下統計報表:
-- 學號,企業管理,馬克思,UML,數據庫,物理,課程數,平均分
select sno as 學號
,max(case when cno = 1 then score end) AS 企業管理
,max(case when cno = 2 then score end) AS 馬克思
,max(case when cno = 3 then score end) AS UML
,max(case when cno = 4 then score end) AS 數據庫
,max(case when cno = 5 then score end) AS 物理
,count(cno) AS 課程數
,avg(score) AS 平均分
FROM sc
GROUP by sno
ORDER by avg(score) DESC
116、查詢各科成績最高分和最低分:
以如下形式顯示:課程號,最高分,最低分
select cno as 課程號, max(score) as 最高分, min(score) 最低分
from sc group by cno
select course.cno as '課程號'
,MAX(score) as '最高分'
,MIN(score) as '最低分'
from sc,course
where sc.cno=course.cno
group by course.cno
117、按各科平均成績從低到高和及格率的百分數從高到低順序
SELECT t.cno AS 課程號,
max(course.cname)AS 課程名,
isnull(AVG(score),0) AS 平均成績,
100 * SUM(CASE WHEN isnull(score,0)>=60 THEN 1 ELSE 0 END)/count(1) AS 及格率
FROM sc t, course
where t.cno = course.cno
GROUP BY t.cno
ORDER BY 及格率 desc
118、查詢如下課程平均成績和及格率的百分數(用"1行"顯示):
企業管理(001),馬克思(002),UML (003),數據庫(004)
select
avg(case when cno = 1 then score end) as 平均分1,
avg(case when cno = 2 then score end) as 平均分2,
avg(case when cno = 3 then score end) as 平均分3,
avg(case when cno = 4 then score end) as 平均分4,
100 * sum(case when cno = 1 and score > 60 then 1 else 0 end) / sum(casewhen cno = 1 then 1 else 0 end) as 及格率1,
100 * sum(case when cno = 2 and score > 60 then 1 else 0 end) / sum(casewhen cno = 2 then 1 else 0 end) as 及格率2,
100 * sum(case when cno = 3 and score > 60 then 1 else 0 end) / sum(casewhen cno = 3 then 1 else 0 end) as 及格率3,
100 * sum(case when cno = 4 and score > 60 then 1 else 0 end) / sum(casewhen cno = 4 then 1 else 0 end) as 及格率4
from sc
119、查詢不同老師所教不同課程平均分, 從高到低顯示
select max(c.tname) as 教師, max(b.cname) 課程, avg(a.score) 平均分
from sc a, course b, teacher c
where a.cno = b.cno and b.tno = c.tno
group by a.cno
order by 平均分 desc
或者:
select r.tname as '教師',r.rname as '課程' , AVG(score) as '平均分'
from sc,
(select t.tname,c.cno as rcso,c.cname as rname
from teacher t ,course c
where t.tno=c.tno)r
where sc.cno=r.rcso
group by sc.cno,r.tname,r.rname
order by AVG(score) desc
120、查詢如下課程成績均在第3名到第6名之間的學生的成績:
-- [學生ID],[學生姓名],企業管理,馬克思,UML,數據庫,平均成績
select top 6 max(a.sno) 學號, max(b.sname) 姓名,
max(case when cno = 1 then score end) as 企業管理,
max(case when cno = 2 then score end) as 馬克思,
max(case when cno = 3 then score end) as UML,
max(case when cno = 4 then score end) as 數據庫,
avg(score) as 平均分
from sc a, student b
where a.sno not in
(select top 2 sno from sc where cno = 1 order by score desc)
and a.sno not in (select top 2 sno from sc where cno = 2 order by scoredesc)
and a.sno not in (select top 2 sno from sc where cno = 3 order by scoredesc)
and a.sno not in (select top 2 sno from sc where cno = 4 order by scoredesc)
and a.sno = b.sno
group by a.sno
“java中數據庫的面試題有哪些”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。