课程: SQL Server Fundamentals: Master Basic Query Techniques

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

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.

内容