溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

加入三行,如果一列中相同的值

發布時間:2020-08-07 15:11:21 來源:ITPUB博客 閱讀:159 作者:a1107849370 欄目:MySQL數據庫

有一個Postgres數據庫和表有三個列。 數據結構在外部系統所以我不能修改它。

每個對象由三行(被列element_id——行相同的值在本專欄中代表同一個對象),例如:

key     value            element_id-----------------------------------status  active           1name    exampleNameAAA   1city    exampleCityAAA   1status  inactive         2name    exampleNameBBB   2city    exampleCityBBB   2status  inactive         3name    exampleNameCCC   3city    exampleCityCCC   3

我想要所有的值描述每個對象(名稱、狀態和城市)。

對于這個示例的輸出應該是:

exampleNameAAA   | active    | exampleCityAAA
exampleNameBBB   | inactive  | exampleCityBBB
exampleNameCCC   | inactive  | exampleCityCCC

我知道如何加入兩行:

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';

怎么可能加入三列?


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女