Skip to main content
The PIVOT clause can be used to pivot columns, “rotating” column values into multiple columns (one for each value), creating wider and shorter denormalized tables from longer, more normalized tables.
PIVOT Syntax
For example, given a source table phone_number, which lists each phone number for a customer as a separate record in the table, a pivot operation can be performed, creating a single record per customer with the home, work, & cell phone numbers as separate columns. With this data:
Input
The following pivot operation can be applied:
PIVOT Example
The data will be pivoted into a table like this:
Output