最近在上课时,讲师给我们一道有关T—SQL编程子查询的面试题,在这里分享给有需要帮助的朋友!
首先看一下创建TestScores表的语法:
create table TestScores(
Name varchar(10),
Course varchar(10),
Score int
)
添加数据:
insert TestScores values('张三','语文','81')
insert TestScores values('张三','数学','75')
insert TestScores values('李四','语文','76')
insert TestScores values('李四','数学','90')
insert TestScores values('王五','语文','81')
insert TestScores values('王五','数学','100')
insert TestScores values('王五','英语','90')
查询如下:
方法一:
select * from TestScores where Name not in(select Name from TestScores where Score<=80)
方法二:
select distinct name 学生姓名 from TestScores where name not in (select distinct name from TestScores where score<=80)
以上内容,可供参考!
SELECT Name FROM TestScores GROUP BY Name HAVING MIN(Score) > 80;