sql

chwwwdz 2009-12-08 09:42:20
score表
scoreid course studentid score
1 数学 2 99
2 数学 3 60
3 数学 4 80
4 语文 5 79
5 语文 6 58
6 语文 1 66
7 英语 6 76
8 英语 4 87
9 英语 3 100
10英语 2 69

怎样得到没门课中分数最高的那条记录
...全文
74 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
忆往惜_追风 2010-03-04
  • 打赏
  • 举报
回复
SQL語句又學習了一遍

學習了
a9529lty 2009-12-08
  • 打赏
  • 举报
回复
WITH tmp_table AS
(
SELECT T.SCOREID,
T.COURSE,
T.SCORE,
T.STUDENTID,
ROW_NUMBER() OVER(PARTITION BY T.COURSE ORDER BY T.SCORE DESC) AS RN
FROM SCORE T
)
SELECT
ta.SCOREID,
ta.COURSE,
ta.STUDENTID,
ta.SCORE
FROM
tmp_table ta
WHERE
ta.rn = 1

sharpidd 2009-12-08
  • 打赏
  • 举报
回复
学习了。
Phoenix_99 2009-12-08
  • 打赏
  • 举报
回复
select studentid,course,score from (
select studentid,course,score,row_number() over(partition by course order by score desc) rn from score
) where rn = 1
dawugui 2009-12-08
  • 打赏
  • 举报
回复
select t.* from score t where score = (select max(score) from score where course = t.course)

select t.* from score t where not exists (select 1 from score where course = t.course and score > t.score)
crazylaa 2009-12-08
  • 打赏
  • 举报
回复
select * from score a where not exists( select * from score b where a.score <b.score and a.course = b.course);
crazylaa 2009-12-08
  • 打赏
  • 举报
回复
select * from score a where not exists( select * from score b where a.score <b.score) group by course;
crazylaa 2009-12-08
  • 打赏
  • 举报
回复
select * from score a where not exists( select * from score b where a.score<b.score);

1,617

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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