日期:2014-05-17  浏览次数:20699 次

求一sql
有如下数据
人员       序号       成绩
001           1             12
001           2             11
001           3             121
001           4             124
001           5             122
001           6             123
002           1             13
002           2             132
002           3             132
002           4             15
002           5             156
003           1             55
003           2             55
003           3             55
003           4             55
003           5             55
003           6             55
003           7             55
003           8             55
如何能求出这些id中按序号升序排列后的后5条数据即001的从2-6   ,002的从1-5,003的从4-8的数据要求按序号从小到大排列



------解决方案--------------------
select peo,id,grade from (select peo,id,grade from aaa where peo =1 order by id desc)
where rownum <= 5

union all
select peo,id,grade from (select peo,id,grade from aaa where peo =2 order by id desc)
where rownum <= 5

union all
select peo,id,grade from (select peo,id,grade from aaa where peo =3 order by id desc)
where rownum <= 5

不怎么样,不过结果是正确的