title: Partial transpose of SQL results
body: <p>I have a table with columns:</p>
  
  <pre><code>ID, N, S, E, W
  </code></pre>
  
  <p>I can easily retrieve a single row of this table with a SELECT</p>
  
  <pre><code>SELECT ID, N, S, E, W from {table name} where ID = 'xxx'
  </code></pre>
  
  <p>Giving me</p>
  
  <pre><code>ID, N, S, E, W
  </code></pre>
  
  <p>However, I would like my results for each ID formatted like this:</p>
  
  <pre><code>ID, N, W, 1
  ID, N, E, 2
  ID, S, E, 3
  ID, S, W, 4
  </code></pre>
  
  <p>In my case, N &amp; S are latitudes, E &amp; W are longitudes, and {N, S, E, W} defines a square in my system. I want to return a point list with a winding order so I can draw them later.</p>
  
  <p>My flavor of SQL is AWS Redshift.</p>
  
  <p>My table is large, so execution speed is a concern. What is an elegant solution?</p>