How can I get a query-based subtotal in a select using group by rollup ?

2024-08-07 Thread dfgpostgres
pg 15.3 on linux I don't even know if the title makes sense, I think it's better explained with an example This is the table... dvdb=# \d dispatch_tracker Table "regr.dispatch_tracker" Column| Type | Collation | Nullable | Default

How to select avg(select max(something) from ...)

2025-02-18 Thread dfgpostgres
Hi: psql 15.3 I have a table with sets of observations, each set sharing an id. I want to get the average of the max of each set. id | val --- 1 5.0 1 4.3 1 3.8 2 4.8 2 6.0 2 2.9 3 4.1 3 4.4 3 8.0 So I want the avg of the max of the set where id=1 (5

Re: PG Unpivot ?

2025-11-03 Thread dfgpostgres
Wow ! That did it, even with the predicate I stuck on the end when I tried it. Thanks Depesz ! On Mon, Nov 3, 2025 at 12:22 PM hubert depesz lubaczewski wrote: > On Mon, Nov 03, 2025 at 12:18:55PM -0500, dfgpostgres wrote: > > psql (13.2, server 15.3) on linux > > > > I

PG Unpivot ?

2025-11-03 Thread dfgpostgres
psql (13.2, server 15.3) on linux I think they call this "unpivot" in MSSQL ? How can I get an sql query to return one line per column with... an ID, column name and value. the ctid for the id field is fine. Example: dvdb=# create table unpivot (intcol integer, floatcol float, strcol varchar);