PIVOT and UNPIVOT in SELECT Statement

In reporting and analytics, we often need to rotate data — turning rows into columns or columns into rows.SQL provides two powerful operators for this purpose: PIVOT and UNPIVOT. Let’s explore them step by step with examples from the HR schema. Example 1: Pivoting Employee Count by Job and Department This query counts employees by […]