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 - SQL Server Tutorial
From the course: Querying Microsoft SQL Server 2022
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
(Locked)
What is a subquery?5m 14s
-
(Locked)
Use a subquery in a HAVING clause6m 26s
-
(Locked)
Correlated subqueries6m 29s
-
(Locked)
PIVOT the result set4m 20s
-
(Locked)
Challenge: Write a query with a subquery1m 2s
-
(Locked)
Solution: Write a query with a subquery8m 49s
-
(Locked)
Solution: Obtain information with a subquery5m 44s
-
(Locked)
-
-
-