xCloudx8 xCloudx8 - 3 months ago 23
SQL Question

Range values SQL

I have a column with values from '10000023' TO '50000000', i need to create a second column filling in for every row from 10000023 to 10000023+500 and go on.

Eg.

Pos | Interval_pos

10000023 100000523
10000523 100001023
... ...
49999500 50000000


is there any way?

Answer

Use generate_series():

select pos, pos + 500
from (select generate_series(minpos, maxpos - 500, 500) as pos
      from (select min(pos) as minpos, max(pos) as maxpost
            from t
           ) t
     ) t
Comments