Given this instruction:
"You’ve been given a database for an online streaming service that first released in 2020. The database has a table customers
with a column net_new
that records net new monthly subscriptions to the streaming service broken down by tiers: free, standard, and premium.
Write a SELECT
statement using windows functions to calculate two new columns from net_new
:
total
: this column should contain a running total count of customers partitioned by the three subscription tiersyear_over_year
: for each month, this column should subtract thenet_new
value 12 months earlier from the currentnet_new
value. This calculation should also be partitioned bylevel
. Use the default LAG behaviour for the first 12 months (2020), which will be null.
Your final SELECT
query should have the columns year
, month
, level
, total
, and year_over_year
in that order. Do not apply any additional order by
statements, other than the ones needed within the window functions to properly perform the calculation."
My solution code:
I am stucked. Can someone help me out? What is wrong with my solution?
THANKS in advance!