Sitemap
SQL Explained

SQL Explained is your go-to publication for mastering SQL, from basics to advanced queries. Learn best practices, optimizations, and real-world applications through clear, concise, and practical insights. Perfect for beginners and experts alike! 🚀 #SQL #Data

Member-only story

Advanced SQL Tutorial Part 5 — SQL PIVOTING 🔨

--

Press enter or click to view image in full size
Photo by Anastasiia Chepinska on Unsplash

Pivoting involves rotating a table by converting unique values from a single column into multiple columns. This rearrangement turns rows into column values, often involving aggregations on remaining columns.

On the other hand, unpivoting reverses this operation by transforming columns into row values.

Database Support for Pivoting and Unpivoting:

🟠SQL Server:

  • Supports both PIVOT and UNPIVOT operators.

🟠Oracle:

  • Supports PIVOT and UNPIVOT (from Oracle 11g).

🟠PostgreSQL:

  • Does not have built-in PIVOT/UNPIVOT, but can simulate using CASE/FILTER for pivoting and UNION ALL or LATERAL for unpivoting.

🟠MySQL:

  • No built-in PIVOT/UNPIVOT. Use CASE and GROUP BY for pivoting, and UNION ALL for unpivoting.

🟠SQLite:

  • No built-in PIVOT/UNPIVOT. Similar to MySQL, use CASE and GROUP BY for pivoting, and UNION ALL for unpivoting.

🟠IBM Db2:

  • Supports PIVOT and UNPIVOT (as of Db2 11.1).

🟠Snowflake:

  • Supports PIVOT and UNPIVOT.

--

--

Shaloo Mathew
Shaloo Mathew

Written by Shaloo Mathew

I love working with data and finding the stories it tells. Through analytics and technology, I aim to turn data into useful insights.

SQL Explained
SQL Explained

Published in SQL Explained

SQL Explained is your go-to publication for mastering SQL, from basics to advanced queries. Learn best practices, optimizations, and real-world applications through clear, concise, and practical insights. Perfect for beginners and experts alike! 🚀 #SQL #Data