0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PostgreSQLで一定間隔でスキップして取得

Last updated at Posted at 2019-08-23

100番目、200番目、300番目...というように一定間隔で行を取得したいとき

SQL

SELECT * FROM (
    SELECT row_number() OVER (ORDER BY id) AS rn, *
    FROM users
) AS rn_q
WHERE MOD(rn, 100) = 0

row_numberを振ってMODで一定間隔にフィルタする

参考

SQL - 【SQL】【Oracle】指定した行数ずつデータを取得する方法|teratail
https://teratail.com/questions/102682

PostgreSQLで連番付与(PostgreSQLでもROWNUM使いたい) - 屑プログラマの憂鬱
http://artisan.hatenablog.com/entry/20130324/1364109795

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?