sql - select a "fake" column that is a range of specific numbers -
i need select table's a information along range of specific numbers, is, every a.id want show every number in range, using postgresql 8.4.
let's suppose range numbers 123, 175 , 192, result want:
rangea.id
123 1
175 1
192 1
123 2
175 2
192 2
123 3
175 3
192 3
i know can achieve using
select range, a.id inner join generate_series(1, 100, 1) range on true
but thing is, don't want use generate_series
because range random numbers, there way it?
maybe this:
select range, a.id range in (123, 175, 192) group range, a.id;
given comment:
for every a.id want show every number of range
this creates called cartesian product
. here's 1 generic option using cross join
union all
:
select a.id, r.rng cross join ( select 123 rng union select 234 union select 556 union select 653 union select 634) r
Comments
Post a Comment