1
I started studying databases, I am using Postgres and I came across the following need, I have field "packages" in one in the table "flow", where I need to separate the packages by quantity of "bytes" (another record of the same table), I can make this presentation separately with the following selects:
select idpontocli,sum(pacotes) as "<128" from fluxo
where idpontocli= 51 and fluxo.time between '2020-05-23 11:15:00' and '2020-05-23 11:25:00' and (bytes/pacotes) <= 128
group by dpontocli;
select idpontocli,sum(pacotes) as "<256" from fluxo
where idpontocli= 51 and fluxo.time between '2020-05-23 11:15:00' and '2020-05-23 11:25:00' and (bytes/pacotes) > 128 and (bytes/pacotes) <= 256
group by idpontocli;
I would like to know if there is a possibility in the same select to make this separation and present a result of the kind:
idpontocli | <128 | <256 | <512 ...
Search by pivot.
– anonimo
Now that I’ve noticed that although I’ve tagged
sql-server
in the text you inform Usepostgres
. For the case of Postgresql seecrosstab
intablefunc
https://www.postgresql.org/docs/current/tablefunc.html.– anonimo
This answers your question? Help with a PIVOT ( Sql Server )
– Sorack
Related: Add rows with the same ID in additional columns.
– Sorack