title: Redshift SQL: swap and aggregate row to column
body: <p>Here's a table T1 in Redshift:</p>
  <p><a href="https://i.stack.imgur.com/PQ7bV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PQ7bV.png" alt="enter image description here" /></a></p>
  <p>I am trying to create a query to represent it in the following manner:</p>
  <p><a href="https://i.stack.imgur.com/eZjD9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eZjD9.png" alt="Transformed reporting layout" /></a></p>
  <p>What is the most optimal way to construct the query. The input table is created dynamically in another SQL query and the resultset of that query will not be small - like 400 to 500 rows / 3 columns.</p>
  <p>Greatly appreciate any hints, suggestion, or solution to go about it.</p>