-2

I am trying to merge the rows x1..x3 in a single column based on the unique identification of postal code.

Current table:

postalcode x1 x2 x3
T2Z4Y6 -113.97203 -113.972029 -113.972027
T2Z0H4 -113.972411 -113.972783 -113.97294

And, I want to transpose the same in rows as below:

postalcode x
T2Z4Y6 -113.97203
T2Z4Y6 -113.972029
T2Z4Y6 -113.972027
T2Z0H4 -113.972411
T2Z0H4 -113.972783
T2Z0H4 -113.97294

How can I do the same in SQL?

  • 2
    The tag SQL-Server is for the product by Microsoft. If you're using BigQuery, tag it as that. They have different syntax, behaviour, etc, as you can see from the answer you commented on. – MatBailie Aug 06 '22 at 23:02

1 Answers1

1

You can use UNION ALL. For example:

select postalcode, x1 as x
union all select postalcode, x2
union all select postalcode, x3
...
union all select postalcode, x10
The Impaler
  • 45,731
  • 9
  • 39
  • 76