成绩表有三个字段:学号、班级、成绩,如何将每个班的前三名的信息取出来?
解决方案 »
- delphi7 “没有注册类别”
- 有谁知道 TRzNavigatorButton 对应的几个按钮值是如何定义的
- delphi8中要使用"PInteger"类型怎么办
- 如何掌握DELPHI
- COM+中返回_Connection的问题,求助!
- 如何设置控件之间的相对大小
- 最简单的问题,很急.
- 如何把DXDBGRID的GRIDLINES画成虚线?
- 想了解一下:要学好计算机——特别是编程,就一定得学好数学?
- 急!!如何制作数据库软件,同时把其中的数据能提出来??
- 有关smtp发送邮件的所有Windows API ?
- application.messagebox 弹出后,为什么要连续2次确认才能执行后面的语句?
group by 班级
order by 成绩
group by 班级
2. top是指最后结果集的前几条,不是分组的前几条
3. order by不能写在group by前面
Declare @t table(id int,StudentNum varchar(10),class varchar(10),score dec(4,2))
insert @t select 1,'001','01-1',10
union all select 2,'002','01-1',20
union all select 3,'003','01-1',30
union all select 4,'004','01-3',40
union all select 5,'005','01-3',50
union all select 6,'006','01-3',60
union all select 7,'007','01-1',70
union all select 8,'008','01-3',80
--sql statement
select *
from @t A
where id in (select top 3 id from @t where class=A.class order by id desc )
order by class,score desc
select *
from @t A
where not exists
(select 1 from @t where class=A.class and score<A.score having count(1)<1)
order by class,score desc