当前位置: 代码迷 >> Oracle开发 >> group by 后拣选每一类前三个插入另一个表中
  详细解决方案

group by 后拣选每一类前三个插入另一个表中

热度:26   发布时间:2016-04-24 07:05:06.0
group by 后选取每一类前三个插入另一个表中
如题,表为EMP(ename,sal,score)
将各个职位成绩前3位的职员的姓名,工资,成绩,名次存到一个数据表GOOD中。

不知道在group by 和Order by之后怎么选取每一类的前三个啊?
rownum貌似不对啊。

------解决方案--------------------
insert into good
select * from (
select * row_number() over(partition by 职位 order by score desc) sc_order from emp
)
where sc_order <= 3
  相关解决方案