展开全部
插入测试记录:
[sql] view plain copy
insert into students values('数学','Jack','Tianjin',80)
insert into students values('数学','Jordan','Tianjin',80)
insert into students values('数学','James','Beijing',55)
insert into students values('英语','Jack','Tianjin',90)
insert into students values('英语','Jordan','Tianjin',60)
insert into students values('英语','James','Beijing',100)
insert into students values('语文','Jack','Tianjin',60)
insert into students values('语文','Tom','Tianjin',77)
insert into students values('语文','Jordan','Tianjin',68)
想要抓取每个科目第一名的整条e69da5e6ba903231313335323631343130323136353331333365643561信息,可以使用Row_number()函数:
select *
from (
select course,stu_name,city,score,ROW_NUMBER() over(partition by course order by score desc) as rn
from students
) a
where a.rn <=1;