【问题标题】:How can I select 10th, 20th, 30th ... row of the result of another select query如何选择另一个选择查询结果的第 10、20、30 ... 行
【发布时间】:2016-01-19 09:43:35
【问题描述】:

我有一张表,其中有一列 tofromID。我只需要选择每 10 个 ID 的行,即从 AB

【问题讨论】:

  • 如果您的 DBMS 支持窗口聚合函数,您可以简单地使用 ROW_NUMBER 模 10
  • 你的 DBMS 是什么,是否支持 ROW_NUMBER?
  • 您使用的是哪个 DBMS?
  • 那么 ROW_NUMBER 没关系,你可以像 dnoeth 说的那样去

标签: sql oracle oracle12c


【解决方案1】:
select * from 
(select * from table where from = 'A' and to ='B' order by ID)
where mod(rownum/10,1) = 0

它首先只取从“A”到“B”的那些,然后给它们rownums,并只选择那些在第10个20个ETC位置的..

【讨论】:

【解决方案2】:

或者你可以直接使用

select from, to, id 
from table1 
where id like'%0' and from ='A' and to = 'B'

【讨论】:

  • 谁说ID是连续的?他想要第 10 个不是 id = 10 和 id = 20
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-08
  • 1970-01-01
  • 1970-01-01
  • 2022-01-17
  • 2011-03-13
  • 2019-09-06
  • 1970-01-01
相关资源
最近更新 更多