Is possible to pivot this table directly in a single sql query? (the table is the result of a query)
From this:
| timestamp | sensor_id | value |
|----------------------|-----------|-------|
| 2021-09-09 02:00 +02 | 58 | 31.7 |
| 2021-09-09 02:00 +02 | 60 | 45.8 |
| 2021-09-09 03:00 +02 | 58 | 81.9 |
| 2021-09-09 03:00 +02 | 60 | 100.8 |
to this:
| timestamp | 58 | 60 |
|----------------------|-----|------|
| 2021-09-09 02:00 +02 | 31.7| 45.8 |
| 2021-09-09 03:00 +02 | 81.9| 100.8|
This is the actual query that create the first table
select TIMESTAMP AT TIME ZONE 'CETDST' AS TIMESTAMP,sensor_id,value
FROM measure
WHERE sensor_id IN (58,60)
AND TIMESTAMP AT TIME ZONE 'CETDST' BETWEEN '2021-09-09 02:00' AND '2021-09-09 03:00'
ORDER BY TIMESTAMP
Is it possible? Can you help me? PostgreSQL v.12