2017-09-07 90 views
-2

欲同一列的值連接成單獨的列級聯列的值轉換成單獨的列

假設有列稱爲類型和文本

TYPES TEXT 
A  This is a 
B  This is b 
C  This is c 

我想所需的輸出爲:

Con 
This is c | This is a 
This is c | This is b 
+2

什麼是你嘗試的事情?此外,您的問題仍然顯得模糊 – Pratik

+0

請解釋並格式化您的問題 – slesh

+0

您如何確定要連接的值? – jarlh

回答

0

我認爲自加入表可以幫助你:

這是僞代碼

select t.text || tb.text || tc.text 
from t 
inner join t tb using(types) 
inner join t tc using(types) 

所以,來連接A和C柱,你可以嘗試以下操作:

select t.text || tc.text 
from t 
full outer join t tc using(types) 
where t.types = 'A' and tc.types = 'C' 
+0

嘗試,獲得預選賽錯誤 – Mahi

+0

和輸出是這爲c該C – Mahi

+0

正如我所說的,這是僞代碼,你需要把它重構爲您的RDBMS – slesh

0
select concat(t1.text ,' | ', t2.text) from tablename t1 
inner join tablename t2 
on t1.types <> t2.types 

SQL Fiddle