PIVOT
PIVOT is a SQL statement in the SELECT Queries category. Rotates rows into columns — converts unique values from one column into multiple columns. SQL Server/Oracle. The syntax is SELECT ... FROM (source_query) PIVOT (agg_func(value) FOR pivot_col IN (value_list)) AS alias;. It returns cross-tabulated result. A typical example: SELECT * FROM ( SELECT dept, salary FROM employees ) src PIVOT ( SUM(salary) FOR dept IN ([IT], [HR], [Sales]) ) AS pvt; -- Departments become columns with total salary values A close relative is SELECT, which retrieves data from a table. The most fundamental SQL statement. A close relative is SELECT *, which selects all columns from a table. A close relative is SELECT DISTINCT, which returns only distinct (unique) values from the specified columns. More about this category: Core SELECT query clauses — SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT. Related SELECT Queries entries: SELECT, SELECT *, SELECT DISTINCT, WHERE, AND / OR / NOT, IN, BETWEEN, LIKE.