Lesson 3.4 · Pro

Unpivot: turn columns into rows

Reshape a wide report (day1, day2, day3...) into a long table that's easy to chart and filter.

In this lesson

  1. Stack one SELECT per column with UNION ALL
  2. The shorter way: CROSS JOIN LATERAL (VALUES ...)
  3. Then query the long table