- Create a CTE and join the sales and menu tables.
- Use the row_number window function to give a unique row number to every item purchased by the customer.
- Order the items by the order_date
- Select customer_id and product_name for every item where the row_number is '1'
4. What is the most purchased item on the menu and how many times was it purchased by all customers?
- Create a CTE and join the sales and menu tables.
- Use the rank window function to rank every item purchased by the customer.
- Order the items by the numbers or times purchase in descending order (highest to lowest).
- Select 'everything' for every item where the rank is '1'.
Note customer_id: B had a tie with all three items on the menu.
- Create a CTE and join the sales and menu tables to the members table.
- Use the rank window function to rank every item purchased by the customer.
- Order the items by the numbers or times purchase in ascending order (lowest to highest).
- Filter the results to orders made after the join date.
- Select customer and product where rank = '1'.
- Create a CTE and join the sales and menu tables to the members table.
- Use the rank window function to rank every item purchased by the customer.
- Order the items by the numbers or times purchase in descending order (highest to lowest).
- Filter the results to orders made before the join date.
- Select customer and product where rank = '1'.
- Create a CTE and join the sales and menu tables to the members table.
- Get the customer_id, total number of items and the total amount spent.
- Filter the results to orders made before the join date.
- Group by the customer id.
9. If each $1 spent equates to 10 points and sushi has a 2x points multiplier - how many points would each customer have?
- Create a CTE and join the sales and menu tables to the members table.
- Use a case statement inside of the sum function to calculate total points including 2x multiplier.
- Filter the results to orders made before the join date.
- Group by the customer id.
10. In the first week after a customer joins the program (including their join date) they earn 2x points on all items, not just sushi - how many points do customer A and B have at the end of January?
- Create a CTE and join the sales and menu tables to the members table.
- Use a case statement inside of the sum function to calculate total points including 2x multiplier.
- If the order is after membship or within the 6 days after membership then use the 2x multiplier on all items. Else, only on sushi.
- Filter the results to orders made in Jan 2021.
- Group by the customer id.