Group by a range of values

From: Mike Martin <redtux1(at)gmail(dot)com>
To: pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Group by a range of values
Date: 2020-08-01 12:14:34
Message-ID: CAOwYNKYcQR_Fzx0=L+5LBh6zqDXQuA3_a+ggAm5RZ3G6zHNbOQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Say I have a field of ints, as for example created by with ordinality or
generate_series, is it possible to group by a range? eq

1,2,3,4,5,6,7,8,9,10
step 3
so output is

1 1
2 1
3 1
4 2
5 2
6 2
7 3
8 3
9 3
10 4

thanks

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Torsten Grust 2020-08-01 12:34:54 Re: Group by a range of values
Previous Message John Lumby 2020-07-31 15:48:28 Re: foreign key referencing inheritance parent