From the course: SQL Server Fundamentals: Master Basic Query Techniques

Unlock the full course today

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

Solution: Aggregates

Solution: Aggregates

(upbeat music) - [Instructor] In this solution, we need to consider the order item data as well as the product data together. So I'm going to start by writing up that join. So order item as OI, inner join, because I only want cases where those values match, as P, on OI. Product ID, equals P, dot product ID. And no filtering, the join is going to do all the filtering work that we would need here. So I can go ahead and start writing my aggregate query. So I know that I am counting based on the number of rows returned per variety. So I know I need to return the product variety and then a count star, as number of orders. And to get this aggregate to work, I need to add a group by clause, so it knows how to collapse that data. Make sure I add the column in it, table alias. Give it a test. And there we have it.

Contents