# PIVOT Keyword

### Description

Rotates a table by turning the unique values from one column in the input expression into multiple columns and aggregating results on specified column values

### Syntax

```sql
SELECT non-pivoted_columns, [pivoted_column1], [pivoted_column2], ...
FROM (
  SELECT column_list
  FROM table_name
) AS source
PIVOT (
  aggregate_function(value_column)
  FOR pivot_column IN ([pivoted_column1], [pivoted_column2], ...)
) AS pivot_table;
```

#### Notes

-   Limitation: only supported on known values

### Example

```sql
WITH
    emp AS (
        SELECT
            e.id AS id,
            "'engineering'" AS eng,
            "'devops'" AS dev
        FROM rippling.employee.Employee e
        PIVOT (
                MAX(YEAR(e.start_date)) FOR e.department IN ('engineering', 'devops')
            )
    )
SELECT
    id,
    eng,
    dev
FROM
    emp;
```

Source: https://developer.rippling.com/documentation/rippling-platform/transformations/sql-reference/pivot

> For the complete documentation index, see [llms.txt](https://developer.rippling.com/llms.txt). Public pages have a Markdown version at the same URL with .md added.
