﻿ AdventureWorks: Find the statistical variance of the sales quota for each quarter

# AdventureWorks Database: Find the statistical variance of the sales quota for each quarter

## SQL Query - AdventureWorks: Exercise-108 with Solution

108. From the following table write a query in SQL to return the statistical variance of the sales quota values for a salesperson for each quarter in a calendar year. Return quotadate, quarter, SalesQuota, and statistical variance. Order the result set in ascending order on quarter.

Sample table: Sales.SalesPersonQuotaHistory

Click to view Full table

Sample Solution:

``````SELECT quotadate AS Year, date_part('quarter',quotadate) AS Quarter, SalesQuota AS SalesQuota,
FROM sales.salespersonquotahistory
``````

Sample Output:

```year                   |quarter|salesquota|variance             |
-----------------------+-------+----------+---------------------+
2012-02-29 00:00:00.000|    1.0|    952000|                    0|
2012-05-30 00:00:00.000|    2.0|   1600000|104976000000.00000000|
2012-08-30 00:00:00.000|    3.0|   1352000| 71267555555.55555556|
2012-11-30 00:00:00.000|    4.0|    839000| 93529187500.00000000|
```

## Practice Online

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

﻿

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