Skip to main content

Find Top Customer by Year

HardPremium

You are given the following tables:

orders table:

order_idcustomer_idorder_dateorder_amountdepartment_id
integerintegerdateintegerinteger

departments table:

department_iddepartment_name
integerstring

customers table:

customer_idfirst_namelast_name
integerstringstring

For each of the last 5 years, identify the customer who placed the most orders, i.e. you should have a list of 5 top customers. Your output should have the following columns: year, customer_id, first_name, last_name, total_orders.

Example output:

yearcustomer_idfirst_namelast_nametotal_orders
2020123JohnDoe5