AdventureWorks Database: Find the total products ordered in each specified orders

SQL Query - AdventureWorks: Exercise-95 with Solution

95. From the following table write a query in SQL to find the number of products that ordered in each of the specified sales orders.

Sample table: Sales.SalesOrderDetail

Click to view Full table

Sample Solution:

SELECT DISTINCT COUNT(Productid) OVER(PARTITION BY SalesOrderid) AS ProductCount  
FROM sales.salesorderdetail  
WHERE SalesOrderid IN (45363,45365);

Sample Output:

          13|       43855|
          15|       43661|

SQL AdventureWorks Editor:

Practice Online

Contribute your code and comments through Disqus.

Previous: Find the departments that each have more than 15 employees.
Next: Compute the variance of sales quota for each quarter in a year.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

Share this Tutorial / Exercise on : Facebook and Twitter

SQL: Tips of the Day

Convert Timestamp to date in MySQL Query:

DATE_FORMAT(FROM_UNIXTIME(`user.registration`), '%e %b %Y') AS 'date_formatted'

Database: MySQL

Ref : https://bit.ly/3EJPnMQ