sql语句编写,求大神帮忙

如题所述

第1个回答  2013-08-22
select Name, Score from
    (select *, dense_rank() over(order by Score desc) as N
     from Student) as temp
where N <= 3

结果就是成绩排名前3的所有学生有多少出多少

还有一种方法就是先获取前3的成绩,然后在学生里面找成绩符合其中一个的

select * from Student where Score in
(select distinct top 3 Score from Student order by Score desc)

 PS:再次吐槽下那个机翻..."显示我的姓名和得分前3名的分数。"

第2个回答  2013-08-21

i want to give scholarship to those on top 3 scores(not top 3 persons,as there may be 4 with 100 marks, 3 with 99 marks,5 with 97 marks,... etc)

please use one sql statement to show me the name and score of the top 3 scores.


中文翻译:

我想给前3名成绩(前3人,有可能是100分,99分,有97分,5,...等的奖学金)

请使用一个SQL语句,显示我的姓名和得分前3名的分数。


案例如下:

create table Students
(
    Name varchar(40),
    Score int
)
insert into Students values ('张三',100),('李四',90),('王五',80),('刘麻子',70),('张三2',50)
--sql语句如下:
select top 3 Name,Score from Students order by Score desc //倒序


希望能帮到你!

本回答被网友采纳
第3个回答  2013-08-21
select top (3) Name,Score from Students
order by asc追答

(not top 3 persons,as there may be 4 with 100 marks, 3 with 99 marks,5 with 97 marks,... etc)
不是前3个人,可能有4个100分,3个99分,5个97分

这个意思应该不是要前3名的人,而是要前3高的分数

select top (3) distinct(Score) from Students
order by desc

相似回答