class
|
name
|
score
|
1
|
a
|
75
|
1
|
b
|
91
|
1
|
c
|
54
|
2
|
d
|
66
|
2
|
e
|
75
|
2
|
f
|
39
|
2
|
g
|
42
|
3
|
h
|
23
|
3
|
i
|
98
|
3
|
j
|
85
|
drop table test
create table test
(class char(2) not null,
name char(10) not null,
score int
)
insert into test values('1','a','75');
insert into test values('1','b','91');
insert into test values('1','c','54');
insert into test values('2','d','66');
insert into test values('2','e','75');
insert into test values('2','f','39');
insert into test values('2','g','42');
insert into test values('3','h','23');
insert into test values('3','i','98');
insert into test values('3','j','85');
select * from test where class ='1' and score in (
select max(score) from test where class ='1' )
union
select * from test where class ='2' and score in (
select max(score) from test where class ='2' )
union
select * from test where class ='3' and score in (
select max(score) from test where class ='3' )