首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

求一sql,该如何处理

2012-01-09 
求一sql有如下数据人员序号成绩0011120012110013121001412400151220016123002113002213200231320024150025

求一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

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

热点排行