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.
Solution: Write a query with a subquery - SQL Server Tutorial
From the course: Querying Microsoft SQL Server 2022
Solution: Write a query with a subquery
(upbeat music) - [Instructor] I hope you were able to generate the pivot table results that summarize the number of products in each category. Let's get going with the solution. I currently have the challenge six-start SQL file here on the screen, and I'm just going to execute it right away so we can take a look at the results, and then we'll take a look at the query above. So the results give me two columns. The first one is Category Name and it has the four categories of products. And then we have a count of the Number of Products in each of our categories. Looking up here in the Select statement, we have the first column is the Category Name column and this is coming from the Name field in the Product Category table. The second column is using a Counting function, and it's counting up the number of unique Product IDs from the product table, and it's now putting that as the Number of Products. So that's where these…
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)
-
-
-