Strata Stratch SQL Question - Medium
Strata Stratch SQL Question - Medium
Amazon
ID 10309
Marketing Campaign Success
You have a table of in-app purchases by user. Users that make their first in-app
purchase are placed in a marketing campaign where they see call-to-actions for more
in-app purchases. Find the number of users that made additional in-app purchases due
to the success of the marketing campaign. The marketing campaign doesn't start until
one day after the initial in-app purchase so users that make multiple purchases on the
same day do not count, nor do we count users that make only the same purchases over
time.
Soln1:
with tem as (
SELECT user_id,
FROM marketing_campaign
GROUP BY user_id
FROM tem
Soln2:
FROM
(SELECT user_id,
GROUP BY user_id) a
Medium
Facebook
ID 10064
Highest Energy Consumption DOY
Find the day of the year with the highest energy consumption from Facebook data
centers. Output the day of the year along with the total energy consumption across all
data centers. Round the energy consumption to the nearest whole number.
Soln1:
GROUP BY dayofyear
LIMIT 1
Medium
City of San Francisco
ID 9728
Count the number of inspections with violations that happened to
'Roxanne Cafe' in each year
Count the number of inspections with violations that happened to 'Roxanne Cafe' for
each year. Output the result along with the year. Order the result based on the year in
ascending order.
Soln1:
GROUP BY year
ORDER BY year
Soln2:
SELECT
count(*) AS n_inspections
FROM sf_restaurant_health_violations
WHERE
GROUP BY year
ORDER BY year