首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求SQL!该怎么处理

2013-03-01 
求SQL!表A(分数表):xuehaoxingming kemufenshu1小李 语文601小李 数学701小李 英语802小王 语文802小王 数

求SQL!
表A(分数表):
xuehaoxingming kemufenshu
1小李 语文60
1小李 数学70
1小李 英语80
2小王 语文80
2小王 数学50
2小王 英语60


从表A中查出每个人中考得最高分的科目,结果是:
xingming kemufenshu
小李 英语80
小王 语文80

从表A中查出每个科目中考个最高分的人,结果是:
xingming kemufenshu
小王 语文80
小李 数学70
小李 英语80

很纠结的作业题,希望得到高人讲解!

附加题:
把最高分换成第二高分!

SQL
[解决办法]
xingming kemu fenshu
1:select * from tba as a where fenshu=(select max(fenshu) where tba where a.xingming=xingming)

2:select * from tba as a where fenshu=(select max(fenshu) where tba where a.kemu=kemu)

3:select * from tba as a where fenshu=(select max(fenshu) where tba b where a.xingming=xingming and fenshu<
(select max(fenshu) from tba where b.xingming=xingming)
)

热点排行
Bad Request.