1. 程式人生 > >查詢score中選學一門以上課程的同學中分數為非最高分成績的記錄

查詢score中選學一門以上課程的同學中分數為非最高分成績的記錄

學生成績表

sno 學生編號   cno   專業課程號   degrees成績

今天遇到一個問題  要求查詢表中的各個專業非最高分的同學的成績

找了很多資料   找到了一些解法  但是感覺不好理解

select * from score a where sno in (select sno from score group by sno having count(*)>1) --查詢到選學一門科目以上的人的學號

and

(degrees not in

 (select max(degrees) from score b where a.cno=b.cno group by cno))--

沒能很好的理解最後的過濾條件

後來我想查出最高分的學生學號/專業號/成績  然後用not in否掉 

所有衍生出

查詢成績表中不同科目的最高分的學生號/分數/科目

select * from score s jion (select cno,max(degrees )  degrees from score group by cno ) sc on (sc.degrees=s.degrees and sc.cno=s.cno);

否掉後發現剩下的並不符合要求  結果如下 由於是靠學號否定的 所有各科成績全部否掉了