cswork / libraryOpen practice workspace

Coding questions · Shopify

Analyze Pirate Theme Usage Growth Over Time

This question evaluates a candidate's ability to perform SQL-based data manipulation and time-series analysis, emphasizing joins, aggregation, time-bucketing, and definition of growth metrics to measure feature adoption.

themes

+----+--------------+-----------+
| id | name         | is_pirate |
+----+--------------+-----------+
| 1  | Pirate Red   | true      |
| 2  | Classic Blue | false     |
| 3  | Pirate Gold  | true      |
+----+--------------+-----------+

theme_usage

+----------+------------+---------+---------+
| usage_id | date       | user_id | theme_id|
+----------+------------+---------+---------+
| 101      | 2024-04-01 | 501     | 1       |
| 102      | 2024-04-02 | 502     | 1       |
| 103      | 2024-04-02 | 503     | 3       |
+----------+------------+---------+---------+

revenue

+----------+--------+
| usage_id | amount |
+----------+--------+
| 101      | 4.99   |
| 102      | 4.99   |
| 103      | 6.99   |
+----------+--------+

users

+---------+---------+
| user_id | country |
+---------+---------+
| 501     | US      |
| 502     | CA      |
| 503     | UK      |
+---------+---------+

calendar

+------------+---------+
| date       | month   |
+------------+---------+
| 2024-04-01 | 2024-04 |
| 2024-04-02 | 2024-04 |
| 2024-05-01 | 2024-05 |
+------------+---------+
Scenario

A mobile app sells visual themes; five tables track themes, user activity, revenue, users, and a calendar. Leadership wants to know if Pirate-themed content is gaining traction.

Question

Write a SQL query that shows whether Pirate theme usage is growing over time. Define and compute your own growth metric (e.g., monthly revenue, monthly active users, cumulative installs, etc.). 2) Return a month-by-month time series that can be charted. 3) Briefly explain why the metric you chose captures growth.

Hints

JOIN theme_usage → themes to filter is_pirate, JOIN calendar for month buckets; GROUP BY month; use window functions or lag to compute growth rates.

Pirate Theme Revenue Growth by Month

Table themes

columntypeconstraints
idINTEGERPRIMARY KEY, NOT NULL
nameVARCHAR(50)NOT NULL
is_pirateBOOLEANNOT NULL

Sample data:

idis_piratename
1truePirate Red
2falseClassic Blue
3truePirate Gold

Table theme_usage

columntypeconstraints
usage_idINTEGERPRIMARY KEY, NOT NULL
dateDATENOT NULL
user_idINTEGERNOT NULL, FOREIGN KEY -> users(user_id)
theme_idINTEGERNOT NULL, FOREIGN KEY -> themes(id)

Sample data:

datetheme_idusage_iduser_id
2024-04-011101501
2024-04-021102502
2024-04-023103503

Table revenue

columntypeconstraints
usage_idINTEGERPRIMARY KEY, NOT NULL, FOREIGN KEY -> theme_usage(usage_id)
amountDECIMAL(10,2)NOT NULL

Sample data:

amountusage_id
4.99101
4.99102
6.99103

Table users

columntypeconstraints
user_idINTEGERPRIMARY KEY, NOT NULL
countryVARCHAR(2)NOT NULL

Sample data:

countryuser_id
US501
CA502
UK503

Table calendar

columntypeconstraints
dateDATEPRIMARY KEY, NOT NULL
monthVARCHAR(7)NOT NULL

Sample data:

datemonth
2024-04-012024-04
2024-04-022024-04
2024-05-012024-05

Expected output

A month-by-month time series for Pirate themes showing monthly revenue and the month-over-month (MoM) revenue growth percentage. Revenue is a direct proxy for Pirate theme traction: increasing revenue over time implies more adoption and/or higher monetization of Pirate themes.

monthpirate_revenuerevenue_mom_growth_pct
2024-0416.97NULL
2024-050-100

Hints

  1. JOIN theme_usage to themes and filter is_pirate = TRUE.
  2. JOIN calendar on date to bucket events into months.
  3. JOIN revenue on usage_id to sum Pirate revenue.
  4. GROUP BY month to compute monthly aggregates.
  5. Use LAG over month order to compute month-over-month growth.
  6. LEFT JOIN from a months calendar to include months with zero usage so charts show continuous time.