Dan*_*aca 4 sql sybase transpose unpivot linear-algebra
我不知道这个操作是否有名称,但它类似于线性代数中的转置.
有没有办法转1表n表如T1
c_1|c_2|c_3|...|a_n
-------------------
1 |2 |3 |...|n
Run Code Online (Sandbox Code Playgroud)
进入一个2表,如下所示
key|val
-------
c_1|1
b_2|2
c_3|3
. |.
. |.
a_n|n
Run Code Online (Sandbox Code Playgroud)
我假设T1中的每一列c_i都不太可能被识别出来.
基本上,您需要UNPIVOT这些数据,您可以使用以下命令执行此操作UNION ALL:
select 'c_1' col, c_1 value
from yourtable
union all
select 'c_2' col, c_2 value
from yourtable
union all
select 'c_3' col, c_3 value
from yourtable
Run Code Online (Sandbox Code Playgroud)