How can I select 10th, 20th, 30th … row of the result of another select query

守給你的承諾、 提交于 2019-12-24 14:49:26

问题


I have a table with a column to, from and ID. I need to select only rows with every 10th ID which is from A to B.


回答1:


select * from 
(select * from table where from = 'A' and to ='B' order by ID)
where mod(rownum/10,1) = 0

It first takes only those from 'A' to 'B', then giving them rownums, and selecting only those in the 10th 20th ETC places..




回答2:


Or you can just use

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


来源:https://stackoverflow.com/questions/34873334/how-can-i-select-10th-20th-30th-row-of-the-result-of-another-select-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!