用游标如何实现
请教下大家:
如果有一张成绩表,成绩表中包含了五个科目的成绩,相当于一个学生有五条记录在里面,那么如果要得到每个成绩的前三名。用游标如何实现呢?
[解决办法]
用什么游标?
select top 3 * from table where 科目 = 要查询的科目 order by 成绩
[解决办法]
select top 3 * from t_table
where
classname = 'math'
order by score_math desc
[解决办法]
id 学号 科目 成绩
idstu_idsubjectscore
11a90
21b80
31c87
42a78
52b98
62c88
73a60
83b67
93c76
104a99
114b98
124c87
135a67
145b76
155c78
select * from
(
select
stu_id ,
subject,
score,
rank() over (partition by subject order by score desc) as row_num
from tscore
) t
where t.row_num < 4