sqlserver查詢各系各科成績最高分的學生的學號,姓名

2021-07-13 09:10:52 字數 3383 閱讀 2905

1樓:sql的藝術

select

a.sno 學號,a.sname 姓名,a.sdept 系名,c.cname 課程名稱,b.maxgrade 成績

from

student a

inner join (select cno,max(sno) sno,max(grade) maxgrade from sc group by cno) b on a.sno=b.sno

inner join course c on b.con=c.cno

2樓:匿名使用者

select student.sno,student.sname,student.sdept,

course.cname,t.maxgrade from

student,course,

(select  s.sno,c.sdept,s.cno,c.maxgrade

from sc s,student st,

(select a.sdept,b.cno,max(b.grade) as maxgrade

from student a,sc b where a.sno=b.sno

group by a.sdept,b.cno) c

where s.sno=st.sno and st.sdept=c.sdept and

s.grade=c.maxgrade) t where student.sno=t.sno

and course.cno=t.cno order by course.cname,student.sdept;

上述語句已經測試通過。**思路是:

學生表與成績表基於學號進行連線獲取每個學號所在系名,然後用院系和課程號對成績表分組彙總,求得每個院系、每個課程的最高得分(結果集c,含系名、課程號和最高分)。然後用結果集c再次與成績表、學生表進行比對,篩選出獲得每個系、每個課程的最高分的學號幷包含課程號和系名(結果集t)。最後t通過連線獲取學生表中的學生姓名、課程表中的課程名完成最後輸出。

3樓:me孤魂

因為不知道3個表的具體結果只能推測3個表的關聯情況學生表student 的學號sno 和成績表sc 的學號sno關聯課程表course的課程cno和成績表sc 的課程cno關聯首先獲得sc表中每門課程的最高成績,然後跟sc關聯獲得其他資訊,在分別去學生表,課程表關聯,獲得具體的資訊

語句如下

select a.sno,c.sname,c.

sdept,d.cno,b.grade from sc a,(select cno,max(grade) grade from sc group by cno) b,student c,coursed d

where a.cno=b.grade

and a.sno=c.sno

and a.cno=d.cno

sql sever 2008r2查詢各系各科成績最高分的學生的學號,姓名,系名,課程名稱,成績

4樓:sql的藝術

select

a.sno 學號,a.sname 姓名,a.sdept 系名,c.cname 課程名稱,b.maxgrade 成績

from

student a

inner join (select cno,max(sno) sno,max(grade) maxgrade from sc group by cno) b on a.sno=b.sno

inner join course c on b.con=c.cno

5樓:匿名使用者

select student.sno,student.sname,student.sdept,

course.cname,t.maxgrade from

student,course,

(select  s.sno,c.sdept,s.cno,c.maxgrade

from sc s,student st,

(select a.sdept,b.cno,max(b.grade) as maxgrade

from student a,sc b where a.sno=b.sno

group by a.sdept,b.cno) c

where s.sno=st.sno and st.sdept=c.sdept and

s.grade=c.maxgrade) t where student.sno=t.sno

and course.cno=t.cno order by course.cname,student.sdept;

上述語句已經測試通過。**思路是:

學生表與成績表基於學號進行連線獲取每個學號所在系名,然後用院系和課程號對成績表分組彙總,求得每個院系、每個課程的最高得分(結果集c,含系名、課程號和最高分)。然後用結果集c再次與成績表、學生表進行比對,篩選出獲得每個系、每個課程的最高分的學號幷包含課程號和系名(結果集t)。最後t通過連線獲取學生表中的學生姓名、課程表中的課程名完成最後輸出。

6樓:匿名使用者

好的,這個涉及到分組排序子查詢等

用sql命令建立一個名為“v單科最高分”的檢視,用於查詢每門課程的最高分的學生學號、姓名、課程號、成績 5

7樓:匿名使用者

首先要復找出最高課程的分數,制然後再根據分數,找出最高的學號。樓上的兩位,語法錯誤。

create view v單科最高分 as

select a.學號, b.姓名, a.課程號, c.課程名, a.成績

(select a.* from xs_kc a, (select 課程號, max(成績) 成績 from xs_kc group by 課程號) b

where a.課程號 = b.課程號 and a.成績=b.成績) a, xsqk b, kc c

where a.學號 = b.學號 and b.課程號 = c.課程號

8樓:匿名使用者

create view 'v單科最高du

分'as

select b.學號

zhidao,b.姓名,a.課程號,a.成績專from (select 學號,課程號,max(成績) as 成績,學分屬 from xs_kc group by 課程號) a,

xsqk b

where a.學號=b.學號

9樓:匿名使用者

create view v單科最高分

asbegin

select xs_kc.學號,xsqk.姓名,xs_kc.課程號,max(xs_kc.成績

版權) as 成績

from xs_kc on xs_kc.學號 = xsqk.學號group by xs_kc.課程號end

sql server 2019查詢當前資料庫中的儲存過程怎麼sql語句怎麼寫啊

檢視函式和過程的狀態 select object name,status from user objects where object type function select object name,status from user objects where object type proced...

怎麼查詢sqlserver中表的的儲存過程

你的意思是 怎樣檢視建立儲存過程的語句嗎?首先要知道 儲存過程名稱 用 sp helptext 儲存過程名 sp helptext 檢視名 sp help 表名 在sql server 語句離執行就可以看到還可以 找到該資料庫 可編譯性 儲存過程 找到儲存過程名稱 右擊 修改 就可以檢視了 檢視哪些...

這樣查詢高考理綜各科成績,怎樣查詢高考理綜的各科成績

一般認為是不可能的,因為選擇題部分的分數是不分開的,即使你看到了非選擇題的答卷,查到了每科的分數,但是選擇題部分都是機器改的,所以不可能查到。省級教育資訊網查。用你的考號和身份證號在教育網上查你的高考成績時會顯示你的名次2 查詢自己的高考全省排名,等高考成績出來後,招生考試網上有公佈一個全省的分數段...