create table test2( id int not null auto_increment, name varchar(10), kecheng varchar(10), fenshu int, primary key(id) ) insert into test2(name,kecheng,fenshu) values('张三','语文',81 ); insert into test2(name,kecheng,fenshu) values('张三','数学',75 ); insert into test2(name,kecheng,fenshu) values('李四','语文',76 ); insert into test2(name,kecheng,fenshu) values('李四','数学',90 ); insert into test2(name,kecheng,fenshu) values('王五','语文',81 ); insert into test2(name,kecheng,fenshu) values('王五','数学',100); insert into test2(name,kecheng,fenshu) values('王五','英语',90 );
-- (1) select name from test2 group by name having min(fenshu) > 80; 王五
-- (2) select distinct name from test2 where name not in (select distinct name from test2 where fenshu<=80)