先分组 在查询每组最新三条数据比如,
1 portal.war 1 2012-08-22 15:58:22 +0800
2 portal.war 1 2012-08-21 15:58:22 +0800
3 portal.war 0 2012-08-20 15:58:22 +0800
4 portal.war 1 2012-08-19 15:58:22 +0800
5 portal2.war 1 2012-08-20 15:58:22 +0800
6 portal3.war 1 2012-08-19 15:58:22 +0800
7 portal.war 0 2012-08-17 15:58:22 +0800显示结果为
1 portal.war 1 2012-08-22 15:58:22 +0800
2 portal.war 1 2012-08-21 15:58:22 +0800
3 portal.war 0 2012-08-20 15:58:22 +0800
5 portal2.war 1 2012-08-20 15:58:22 +0800
6 portal3.war 1 2012-08-19 15:58:22 +0800
谁帮忙看下吧,实在没写出来的

解决方案 »

  1.   

    --假设对应列为id,name,val,dt,还过这种速度不快
    select id,name,val,dt from
    (select row_number() over(partition by name order by dt desc) rn,id,name,val,dt from 你的表) t
    where rn<4;
      

  2.   

    select id,name,val,dt from
    (select row_number() over(partition by name order by dt desc) rn,id,name,val,dt from 你的表  select * from table where rownum<1000 ) t
    where rn<4;刚才添加了一个限制 ,这样的效率高多了,再次谢谢上面的兄弟