Posted On: Feb 23, 2022
Amazon Redshift now supports PIVOT and UNPIVOT SQL operators that can help you transpose rows into columns and vice versa with high performance, for data modeling, data analysis, and data presentation. You can also use PIVOT and UNPIVOT to more easily migrate from your existing data warehouse systems to Amazon Redshift.
With PIVOT, you can create cross tabular data representations, where rows of an input table are transformed into columns of a result table. PIVOT helps you to rotate output from rows to columns, for the purpose of representing tabular data in a format that is easier to read. You can use UNPIVOT to transform columns of an input table into rows of the result table. You can apply PIVOT and UNPIVOT to tables, sub-queries, and common table expressions (CTEs). PIVOT supports the COUNT, SUM, MIN, MAX, and AVG aggregate functions.
Amazon Redshift support for PIVOT and UNPIVOT is available in all AWS commercial regions where Amazon Redshift is available. See AWS Region Table for more details. To learn more about PIVOT and UNPIVOT SQL operators, please visit the documentation.