求SQL!

lb06008401 2013-02-22 01:54:43
表A(分数表):
xuehao xingming kemu fenshu
1 小李 语文 60
1 小李 数学 70
1 小李 英语 80
2 小王 语文 80
2 小王 数学 50
2 小王 英语 60


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

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

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

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

...全文
1629 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lb06008401 2013-02-22
  • 打赏
  • 举报
回复
引用 3 楼 szm341 的回复:
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……
1.select * from A as t where t.fenshu=(select max(fenshu) from mr_test where t.xingming=xingming) 2.select * from A as t where t.fenshu=(select max(fenshu) from mr_test where t.kemu=kemu) 3.select * from A t where t.fenshu=( select max(fenshu) from A b where t.xingming=xingming and fenshu<(select max(fenshu) from mr_test where b.xingming=xingming)) 谢谢!这个就可以啦!
發糞塗牆 2013-02-22
  • 打赏
  • 举报
回复
我看到你也很纠结。作业题我从来都不做,你自己慢慢练吧
szm341 2013-02-22
  • 打赏
  • 举报
回复
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) )
-Tracy-McGrady- 2013-02-22
  • 打赏
  • 举报
回复
算了,自己多练练
-Tracy-McGrady- 2013-02-22
  • 打赏
  • 举报
回复
select xingming,kemu,fenshu=max(fenshu) from A group by xingming,kemu

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧