Suppose there is a table:

CREATE TABLE example_table ( datetime timestamp without time zone NOT NULL, revenue smallint NOT NULL, ); 

And I make a request from it:

 select datetime,revenue from example_table where datetime between "..." and "..." order BY datetime; 

But I need to get, say, every 5th line of this query. Can this be done? Without adding a SERIAL field.

    1 answer 1

    Solution to the forehead: number the sample through row_number and get the rows for which row_number is a multiple of 5.

     select datetime, revenue from ( select datetime,revenue, row_number() over() as rn from example_table where datetime between "..." and "..." order BY datetime ) subquery where rn % 5 = 0; 

    A serial will not help you.