查詢每門課程成績都大於80分學生的學號


1 查詢每門課程成績都大於80分學生的學號 
數據庫 表 student
name score course
A 85  語文
A 75  數學
A 82  英語
B   75  語文
B   89  數學
B   79  英語
天使美眉90 語文
天使美眉100 數學
天使美眉100 英語

請找出每門課程都超過80分的那個人名字的SQL語句

SQL1:

select name from test.stu
group by name
having count(score) =sum(case  when score>80 then 1 else 0 end )

SQL2:

select name from stu
group by name
having name not in (
select name from stu
where score <80)

SQL3:

select name from test.stu
group by name
having min(score)>=80

 

select distinct name from student  where  name not in (select distinct name from student where fengshu<=80)

group by與distinct 區別

select name from student
group by name

等價於

select distinct name from student

但是group by效率更高都是以group by name后面的列名來分組只是后面的判定要和having連用


免責聲明!

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



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