| 发表于:2007-07-01 09:44:285楼 得分:10 |
简单! 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 | | |
|