您好,请问如何用SQL语言查询mokao表中4次模考中后3次考试数学成绩均在80分以上的学生?(每一行为考生姓名、编号、模考轮次、模考成绩等等的数据)。且输出要所有要素按姓名输出,排序按照第四次模考的成绩?或按照后3次模考的平均分?
如:
考生姓名(nam) 编号(cod) 模考轮次(tern) 模考成绩(sco)
nam cod tern sco
A 1 1 85
B 2 3 79
C 3 2 95
B 2 1 77
A 1 4 90
C 3 1 81
A 1 3 85
B 2 4 98
C 3 3 88
A 1 2 97
B 2 2 97
C 3 4 79
查询后输出为:
nam cod tern sco
A 1 1 85
A 1 2 97
A 1 3 85
A 1 4 90
--create table mokao(nam varchar(10),cod varchar(10),tern int,sco numeric(6,2))
--insert into mokao(nam,cod,tern,sco) values('a','1',1,85)
--insert into mokao(nam,cod,tern,sco) values('a','1',2,97)
--insert into mokao(nam,cod,tern,sco) values('a','1',3,85)
--insert into mokao(nam,cod,tern,sco) values('a','1',4,90)
--insert into mokao(nam,cod,tern,sco) values('b','2',1,85)
--insert into mokao(nam,cod,tern,sco) values('b','2',2,97)
--insert into mokao(nam,cod,tern,sco) values('b','2',3,79)
--insert into mokao(nam,cod,tern,sco) values('b','2',4,91)
--insert into mokao(nam,cod,tern,sco) values('c','3',1,85)
--insert into mokao(nam,cod,tern,sco) values('c','3',2,97)
--insert into mokao(nam,cod,tern,sco) values('c','3',3,77)
--insert into mokao(nam,cod,tern,sco) values('c','3',4,97)
select * from mokao where nam in( select nam from (select * from mokao where tern >=2 and sco >=80)a group by nam having count(*)>=3)