oracle 求前10%最高消费数据

select member.membername   姓名,
       hh.cardnumber       卡号,
       member.idcardnumber 电话,
       hh.points           积分
  from (SELECT pointcard.cardnumber,
               pointcard.memberid,
               pointcard.totpoints,
               pointcard.points,
               sign(CUME_DIST() OVER(ORDER BY totpoints DESC) - 0.1) s1
          FROM pointcard) hh,
       member
 where hh.memberid = member.memberid
   and hh.s1 < 0
 order by totpoints desc, cardnumber

参考网友的代码 如下:

前10%:select sum(a) from (select a,sign(cume_dist() over (order by a asc) - 0.1)) S1) where s1 < 0;
后10%:select sum(a) from (select a,sign(cume_dist() over (order by a asc) - 0.9)) S1) where s1 >= 0;

posted @ 2011-10-09 12:47  aspc  阅读(323)  评论(0编辑  收藏  举报