Oracle: I need to select n rows from every k rows of a table
问题 For example: My table has 10000 rows. First I will divide it in 5 sets of 2000(k) rows. Then from each set of 2000 rows I will select only top 100(n) rows. With this approach I am trying to scan some rows of table with a specific pattern. 回答1: Assuming you are ordering them 1 - 10000 using some logic and want to output only rows 1-100,2001-2100,4001-4100,etc then you can use the ROWNUM pseudocolumn: SELECT * FROM ( SELECT t.*, ROWNUM AS rn -- Secondly, assign a row number to the ordered rows