面试中遇到的sql

1、现有数据库如下,要求查询出每一科成绩都大于80的学生姓名;

表:

方法一:因为需要查出各科都大于80的学生姓名,那么一旦有一门课成绩小于80那么便不符合条件,我们只需要查出成绩小于80的学生,然后not in 即可;

sql:

select distinct(username) from student where username not in (select username from student where score<80);

方法二:使用group by having

sql:

select username from student group by username having min(score>80)


2、根据下表信息删除除了id不相同其他信息都相同的学生信息


sql:

delete student2 where id not in(select min(id) from student2 group by name,age,number);


猜你喜欢

转载自blog.csdn.net/zks_4826/article/details/80799433
今日推荐