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 | 
>
			
            作者:豌豆果果
            
            出处:https://www.cnblogs.com/hylogs/
            
            本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
			
			觉得有所帮助,可以请果果喝咖啡哟^_^!
			
 
	
                    
                
                
            
        
浙公网安备 33010602011771号