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 $1450.00. Show the following columns:
year– the year of registration.week– the week of registration.percent_of_good_customers– 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
customersandorderstables. - Create three columns:
customer_id,registration_date,AVG(total_amount). - Group rows by the
customer_idandregistration_datecolumns.
In the outer query:
- Using the
DATE_PART()function to extract the year and week. - Using the
COUNT()function and theCASE WHENstatement, count the percentage of the "good customers," like so:COUNT(CASE WHEN /* only values over 1450 */ END) * 100.0 / COUNT(/* all values */) AS percent_of_good_customers
- Don't forget about grouping the result by the year and week.




