create
table
studentInfo(
id number(8)
primary
key
,
name
varchar2(20)
not
null
,
ObjectName varchar2(20)
not
null
,
fenshu varchar2(2)
not
null
);
insert
into
studentInfo
values
(1,
'张三'
,
'数学'
,70);
insert
into
studentInfo
values
(2,
'张三'
,
'语文'
,80);
insert
into
studentInfo
values
(3,
'张三'
,
'英语'
,90);
insert
into
studentInfo
values
(4,
'王二'
,
'数学'
,80);
insert
into
studentInfo
values
(5,
'王二'
,
'语文'
,70);
insert
into
studentInfo
values
(6,
'李四'
,
'数学'
,90);
insert
into
studentInfo
values
(7,
'李四'
,
'语文'
,90);
求学员中每一科成绩最高的学员sql
1,select
name
, objectname,fenshu
from
studentinfo st
where
fenshu = (
select
max
(fenshu)
from
studentinfo s
where
st.objectname=s.objectname);
2,
select
name
,ObjectName, fenshu
from
(
select
name
,ObjectName,fenshu,
row_number() over(partition
by
ObjectName
order
by
fenshu
desc
) rn
from
studentInfo
)
where
rn = 1
3,
SELECT a.NAME,a.Objectname,a.fenshu FROM studentinfo a ,
(SELECT Objectname,MAX(fenshu) fenshu from studentinfo t
GROUP BY Objectname ) b
WHERE a.objectname = b.objectname AND a.fenshu = b.fenshu