Cracking the code - Warby Parker Assignment

Hi guys,

I’m in the process to finish the WP assignement but i didn’t get where the error is in the following code.

I’m basically try to calculate the difference in purchase rates between customers who had 3 number of pairs with ones who had 5.

I moved on with the following code but I haven’t get any result so far from the query.

Is there anyone who can help me on the code?

ThX


WITH data AS (
SELECT DISTINCT q.user_id,
h.user_id IS NOT NULL AS ‘is_home_try_on’,
h.number_of_pairs AS ‘A/B variant’,
p.user_id IS NOT NULL AS ‘is_purchase’
FROM quiz q
LEFT JOIN home_try_on h
ON q.user_id = h.user_id
LEFT JOIN purchase p
ON p.user_id = q.user_id
)
SELECT A/B variant,
SUM(CASE
WHEN is_home_try_on = 1
THEN 1
ELSE 0
END) ‘home_trial’,
SUM(CASE
WHEN is_purchase = 1
THEN 1
ELSE 0
END) ‘purchase’
FROM data
GROUP BY 1;

Is this question 5 or 6? What’s the error message? or does nothing print?

double check your second SELECT statement. don’t you want to select “number_of_pairs” in general and group by that? (0, 3 or 5)?

q5. It doesn’t print anything

the idea is to have a table with 3 columns

  • A/B variant (3 pairs vs 5 pairs)
  • home trail : if positive then 1
  • purchase: if positive then 1

Yep, I understand; I did this project a couple years ago.

Concerning CTE’s (WITH statements) you’re not going to see the results printed to the terminal.

Did you look at the hint by any chance?
In your query, remove the "WITH data AS and the parens at the top and bottom and then as the hint states, add LIMIT 10; and then you should see your results.

Your table joins seem to be good.

CASE statements for that task in particular are unnnesesary, the IS NOT NULL statement already returns ‘1’ if it is true.

Also your CASE statements seem to have some syntaxis errors (Check the parenteses).

If you would like to practice using CASE try to turn the 1 values into ‘True’ and any other value into ‘False’, try editing this query’s ‘is_home_try_on’ and ‘is_purchase’ columns:

SELECT DISTINCT q.user_id,
  h.user_id IS NOT NULL AS 'is_home_try_on',
  h.number_of_pairs AS 'A/B variant',
  p.user_id IS NOT NULL AS 'is_purchase'
FROM quiz q
LEFT JOIN home_try_on h
  ON q.user_id = h.user_id
LEFT JOIN purchase p
  ON p.user_id = q.user_id
LIMIT 10;