AdventureWorks Database: Find the TotalSalesYTD of each SalesQuota

SQL Query - AdventureWorks: Exercise-99 with Solution

99. From the following table write a query in SQL to find the TotalSalesYTD of each SalesQuota. Show the summary of the TotalSalesYTD amounts for all SalesQuota groups. Return SalesQuota and TotalSalesYTD.

Sample table: Sales.SalesPerson

Click to view Full table

Sample Solution:

SELECT SalesQuota, SUM(SalesYTD) as "TotalSalesYTD" , 
GROUPING(SalesQuota) as "Grouping" 
FROM Sales.SalesPerson  
GROUP BY rollup(SalesQuota);

Sample Output:

          |36277591.9034|       1|
          | 1252127.9471|       0|
    300000| 7654925.9863|       0|
    250000|27370537.9700|       0|

SQL AdventureWorks Editor:

Practice Online

Contribute your code and comments through Disqus.

Previous: Find total ListPrice and StandardCost of products of distinct color.
Next: Find the sum of the ListPrice and StandardCost for each color.

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