Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Final Quiz
4. Question 3

## Instruction

Good job! Now let's take a look at customer activity.

## Exercise

Find the number of "good customers" in weekly signup cohorts from the first quarter of 2017. Define a good customer as one whose average total order amount was above \$800.00. Show the following columns:

• Year – the year of registration.
• Week – the week of registration.
• PercentOfGoodCustomers – the percent of good customers.

Order the results by year and week.

### Stuck? Here's a hint!

First, you will need to create a CTE that returns the table of customer IDs, their registration dates, and their average order value. In the inside query:

• Join the Customers and Orders tables.
• Create three columns: CustomerID, RegistrationDate, AVG(TotalAmount).
• Group rows by the CustomerID and RegistrationDate columns.

In the outer query:

• Using the DATEPART() function, extract year and week.
• Using the COUNT() function and the CASE WHEN statement, count the percentage of the "good customers," like so:
COUNT(CASE WHEN /* only values over 800 */ END) * 100.0 / COUNT(/* all values */) AS PercentOfGoodCustomers
• Don't forget about grouping the result by the year and week.