Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Add three rows, if the same value in a column

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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?

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report