SELECT rows multiple of x

In SQL Server, how to select rows 10, 20, 30, 40, etc., where RowID is an equal integer break (+10). There are 50k lines, so using IN (1,10,20, etc.) is time consuming.

SELECT * FROM 'TABLENAME' WHERE RowID = 10 (+ 10) 
+6
source share
2 answers

You can use modulo for this.

 SELECT * FROM `table` WHERE (`id` % 10) = 0 SELECT * FROM `table` WHERE (`id` MOD 10) = 0 SELECT * FROM `table` WHERE !MOD(`id`, 10) 

Anyone should do.

+7
source

I suspect you need to use the rowId module operator mod 10 = 0. some of this order.

0
source

Source: https://habr.com/ru/post/949389/


All Articles