查詢每門課程最高分的學生的學號,課程號,成績


成績表score的結構:

如何查詢每門課程最高分的學生的學號,課程號,成績?

答案:

select t1.sid,t1.cid,t1.score
from score t1
where t1.score = 
(
    select max(t2.score)
    from score t2
    where t2.cid = t1.cid
    group by t2.cid
)

如果要知道學生的姓名:

select t1.sid,s.name,t1.cid,t1.score
from score t1
inner join stu s
on t1.sid=s.id
where t1.score = 
(
    select max(t2.score)
    from score t2
    where t2.cid = t1.cid
    group by t2.cid
)

 參考:http://zhidao.baidu.com/link?url=1hVfu2fzddmSlZkn0El-bpyuQHX2egJGRsTLqDs8-UQOwjO5XxlBO_PEZ6yI9Vvpf9oMe-6BXV98W-SIT0ynsiDmhZbX95rL5P49hiPDLe_


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM