SQL經典面試題及答案


1.用一條SQL 語句 查詢出每門課都大於80 分的學生姓名

表名:TRAINING

姓名 課程 分數
name course score
張三 語文 80
張三 數學 78
李四 語文 76
李四 數學 90
王五 語文 81
王五 數學 100
王五 英語 90

答案1:

select distinct name from training where name
not in (select distinct name from training where score <=80
)

答案2:

select name from training group by name having min(score) >80

查詢結果:

name
王五

2.刪除除了自動編號不同, 其他都相同的學生冗余信息

表名:student

自動編號 學號 姓名 課程編號 課程名稱 分數
no stu_no name course_cd course_name score
001 2018001 張三 001 語文 80
002 2018002 李四 002 英語 85
003 2018001 張三 001 語文 80

答案:

delete student where no not in( select min(no) from student  group by stu_no,name,course_cd,course_name,score)

結果:

自動編號 學號 姓名 課程編號 課程名稱 分數
no stu_no name course_cd course_name score
001 2018001 張三 001 語文 80
002 2018002 李四 002 英語 85


免責聲明!

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



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