【问题标题】:Oracle 11g: LIMIT OFFSET on GROUPED dataOracle 11g:限制 GROUPED 数据的偏移量
【发布时间】:2016-04-04 00:50:55
【问题描述】:

我有以下查询和结果集

第一个数据未分组,第二个数据按“类别”分组。我的目标是对这些分组数据使用分页,但是由于 Oracle 11g 不支持 LIMIT 和 OFFSET,这已经成为一个问题。

我研究了这个问题的想法;

How to add offset in a "select" query in Oracle 11g?

但是我不想使用 WHERE 子句,因为它会从组中排除记录。

SELECT MAX(tb_test_1.category) as category, COUNT(tb_test_1.category) as count 
FROM tb_test_1 
GROUP BY tb_test_1.category

谁能告诉我如何在 Oracle 11g 的上述查询中使用 LIMIT 和 OFFSET?

谢谢

【问题讨论】:

标签: sql oracle oracle11g pagination rownum


【解决方案1】:

这是广为人知的问题,可能存在很多已回答的重复项,但无论如何,在您的情况下,此查询应该有效:

select * from (

    select rownum offset, rs.* from (

       SELECT MAX(t.category) as category, 
              COUNT(t.category) as count 
         FROM tb_test_1 t 
        GROUP BY t.category
        /* add order by clause here if needed */

   ) rs

) where rownum <= 10 /* limit */
    and offset >= 0 /* offset */

【讨论】:

  • 正是在标记为重复的主题中已回答的内容。
猜你喜欢
  • 2011-11-11
  • 1970-01-01
  • 2019-06-06
  • 1970-01-01
  • 2015-01-21
  • 2016-04-07
  • 2020-01-23
  • 1970-01-01
  • 2016-06-09
相关资源
最近更新 更多