Ben Gorman

Ben Gorman

Life's a garden. Dig it.

Challenge

You've created an app :mobile_phone: to help people lose weight called Don't Weight. You finally have some data on your pilot users, which you can view with the following query.

WITH
 
  user_weights AS (
    SELECT [175.1, 175.2, 173.8, 173.9, 174.5, 174.6] AS weights, "John" as user
    UNION ALL SELECT [233.0, 230.4, 231.8, 1229.6, 230.0] as weights, "Ryan" as user
    UNION ALL SELECT [165.5, 165.0] as weights, "Amber" as user
  )
 
SELECT * FROM user_weights

user weights

Daily weights stored as arrays

Notice! Each user's sequence of weights are stored inside an array.

Each day, your user's must record their weight, as shown in the table above. For example, John weighed 175.1 lbs on the day he installed the app. Five days later (i.e. day 6), he weighed 174.6 lbs - a good sign!

For each user, calculate

  1. How much they weighed on day 1
  2. How much weight they lost between day 1 and day 2
  3. How much weight they lost between day 1 and day 3
  4. How much weight they lost between day 1 and their last day using the app.

Solution

This content is gated

Subscribe to one of the products below to gain access