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
posted @ 2018-10-19 20:04  豌豆果果  阅读(2043)  评论(0编辑  收藏  举报