Re: Group by a range of values
От
Steve Midgley
Тема
Re: Group by a range of values
Дата
Msg-id
CAJexoSJc_HaF3qM_SsvdpEXWnpSBfja9gBi0Kg8QixehvcZPvw@mail.gmail.com
Ответ на
Group by a range of values (Mike Martin)
Список
Дерево обсуждения
Group by a range of values Mike Martin <redtux1@gmail.com>
Re: Group by a range of values Torsten Grust <torsten.grust@gmail.com>
Re: Group by a range of values Rob Sargent <robjsargent@gmail.com>
Re: Group by a range of values Steve Midgley <science@misuse.org>
On Sat, Aug 1, 2020 at 5:15 AM Mike Martin <redtux1@gmail.com> wrote:
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? eq1,2,3,4,5,6,7,8,9,10step 3so output is1 12 13 14 25 26 27 38 39 310 4thanks
My solution would be:
select num, ceiling(CAST (num as float)/3) as grp from AggYields:
num grp
1 1
2 1
3 1
4 2
5 2
6 2
7 3
8 3
9 3
10 4
1 1
2 1
3 1
4 2
5 2
6 2
7 3
8 3
9 3
10 4
For DDL of:
CREATE TABLE Agg
("num" int);INSERT INTO Agg
("num")
VALUES
(1),
(2),
(3),
(4),
(5),
(6),
(7),
(8),
(9),
(10);
I created this in SQL Fiddle: http://sqlfiddle.com/#!17/37519e/30/0
В списке pgsql-sql по дате отправления
От: Mike Martin
Дата: