internalsGet Pro

Module 02 · Lesson 5 of 12Pro

Pivoting and unpivoting data in SQL

Level
Intermediate
Topic
SQL for data engineering
Reading time
16 min

When you finish this page you can

  1. Explain why pipelines store data in long format and pivot only at the edge, where a person or a tool needs a grid.
  2. Pivot a long table with conditional aggregation and with DuckDB’s PIVOT, and say what each does when a new city appears.
  3. Unpivot a wide partner file into rows with UNION ALL or UNPIVOT, and stop the load when an unknown column arrives.
  4. Tell an empty pivot cell from a zero, and keep the difference until the reader needs it.
  1. Design: a first analytics pipeline for an online store30 min
  2. NULLs and messy values in SQL16 min

Tuesday’s grid is ₹2,700 short

is an online store in India. Every night Meera, its data engineer, loads the day’s orders from the store’s database into an analytical copy. Daniel, who leads finance reporting, reads the numbers at 07:00.

Our biggest sale ever · Black Friday

Flat 50% Off

Pro

Continue reading

Unlock every course, now and later

  • System Design, live
  • AI Engineering, live
  • Data Engineering, live
  • Machine Learning Engineering, live
  • Inference Engineering, coming soon
  • AI Research, coming soon
  • Performance Engineering, coming soon
  • Agent & Harness Engineering, coming soon
  • LLM Fine-tuning, coming soon
  • LLM Pre-training & Post-training, coming soon
  • Reinforcement Learning, coming soon
  • AI Infrastructure & Platform Engineering, coming soon
  • AI Evaluation & Safety, coming soon
  • Forward Deployed Engineering, coming soon
  • Cloud Computing, coming soon
  • DevOps, coming soon

50% off · Annual and Lifetime

BLACKFRIDAY50Applied at checkout

Choose a plan