Hello, please someone to help me how I could query this code

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:

  1. total: this column should contain a running total count of customers partitioned by the three subscription tiers
  2. year_over_year: for each month, this column should subtract the net_new value 12 months earlier from the current net_new value. This calculation should also be partitioned by level. Use the default LAG behavior 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.

This sounds like homework or an exam question. I’m sorry, but we cannot help with either. Check the community guidelines.

1 Like

I have successfully managed to debug it, thank you so much.