Patrick Balada
Patrick Balada

Reputation: 1450

How to convert a row into two columns fixing certain columns?

Suppose the following observation in a table:

Var1   Var2   Var3   Var4   Var5   Var6
 a      b      c      d      e      f

Now, I want to have two rows, which differ in Var3/Var4 and in Var5/Var5, respectively. That is:

Var1   Var2   VarX   VarY
 a      b      c      d
 a      b      e      f

Upvotes: 0

Views: 43

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269773

You can use union all:

select var1, var2, var3 as varx, var4 as vary
from t
union all
select var1, var2, var5, var6
from t;

Upvotes: 3

Related Questions