Skip to content

Tag: crosstab

How do I pivot values from rows into column names in Postgres?

I have a query in Postgres. It’s working well and returns exactly the rows I’m looking for. Here’s the query: This is what it returns: id status timestamp 1 started 2022-01-15 05:12:36 1 paused 2022-04-14 09:12:50 1 killed 2022-04-27 13:12:48 How can I pivot this table to return this exactly: id started paused killed 1 2022-01-15 05:12:36 2022-04-14 09:12:50 2022-04-27

How to rotate a two-column table?

This might be a novice question – I’m still learning. I’m on PostgreSQL 9.6 with the following query: My query returns the following dynamic rows: locales count en 10 fr 7 de 3 n additional locales (~300)… n-count I’m trying to rotate it so that locale values end up as columns with a single row, like this: en fr de

crosstab in PostgreSQL

I have the following tables: and How can I query the database so that it returns the table where n ranges over the rows of the table sensor and ‘abbrv $i’ is replaced by the corresponding value in the table sensor? The following query works up to a certain extent: I need to know how many rows there are in

Pivot on Multiple Columns using Tablefunc

Has anyone used tablefunc to pivot on multiple variables as opposed to only using row name? The documentation notes: The “extra” columns are expected to be the same for all rows with the same row_name value. I’m not sure how to do this without combining the columns that I want to pivot on (which I highly doubt will give me