Add three rows, if the same value in a column
There is an Postgres database and tables with three columns. The data structure is in the external system, so I can't modify it.
Each object consists of three rows (the same value of the listed element_id-- row represents the same object in this column), for example:
Key value element_id--status active 1name exampleNameAAA 1city exampleCityAAA 1status inactive 2name exampleNameBBB 2city exampleCityBBB 2status inactive 3name exampleNameCCC 3city exampleCityCCC 3
I want all the values to describe each object (name, status, and city).
The output for this example should be:
ExampleNameAAA | active | exampleCityAAAexampleNameBBB | inactive | exampleCityBBBexampleNameCCC | inactive | exampleCityCCC
I know how to add two lines:
Select a.value as name, b.value as statusfrom the_table a join the_table b on a.element_id = b.element_id and b. "key" = 'status'where a. "key" =' name'
How is it possible to join three columns?