﻿ AdventureWorks: Compute the variance of sales quota for each quarter in a year

# AdventureWorks Database: Compute the variance of sales quota for each quarter in a year

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

96. From the following table write a query in SQL to compute the statistical variance of the sales quota values for each quarter in a calendar year for a sales person. Return year, quarter, salesquota and variance of salesquota.

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|                     |
2012-05-30 00:00:00.000|    2.0|   1600000|209952000000.00000000|
2012-08-30 00:00:00.000|    3.0|   1352000|106901333333.33333333|
2012-11-30 00:00:00.000|    4.0|    839000|124705583333.33333333|
```

## 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'`