From the course: Querying Microsoft SQL Server 2022

Unlock the full course today

Join today to access over 24,200 courses taught by industry experts.

PIVOT the result set

PIVOT the result set

- [Instructor] The standard output of a queries result is to have the data presented as individual rows. Using the PIVOT operator, we can rotate those results, so that the data is displayed in a column format instead. Which may be beneficial for adding to a spreadsheet or another analysis platform. First, let's review the data stored in the product table. We'll select the product line and list price columns out of the production.product table and filter the results to only see products where the product line is not nulled. This gives us the product line and the list price for all 278 products in the database. Now we can summarize this information to find the average list price per product line. I'll modify the select statement to find the average list price and I'll name this column as average price. Then I need a group by clause at the very end and we'll group everything by the product line. Executing the query again shows…

Contents