当前位置:首页 > 开发 > 数据库 > 正文

oracle分组取前3条记录

发表于: 2014-04-18   作者:53873039oycg   来源:转载   浏览:
摘要:   select bb.name, bb.id from (select aa.*, row_number() over(partition by aa.group_id order by aa.name) rn from (select bo.group_id, bc.name, bo.id

 

select bb.name, bb.id
  from (select aa.*,
               row_number() over(partition by aa.group_id order by aa.name) rn
          from (select bo.group_id, bc.name, bo.id
                  from table_a bc, table_b bo
                 where 1 = 1
                   and regexp_instr(bc.name, '测试') = 0
                   and bc.id = bo.ref_id
                 order by bo.id desc) aa) bb
 where bb.rn <= 3

   主要用到了regexp_instr和row_number() over(partition by A order by B)。

    如有错误请指出,谢谢。

    全文完

 

 

oracle分组取前3条记录

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号