Month Over Month
Start Timer
0:00:00
Given a table of transactions and products, write a query to get the month_over_month change in revenue for the year 2019. Make sure to round month_over_month to 2 decimal places.
Note: Return month_over_month as a fraction of the previous month’s revenue (0.04, not 4), and NULL for the first month since it has no prior month.
Example:
Input:
transactions table
| Column | Type |
|---|---|
id |
INTEGER |
user_id |
INTEGER |
created_at |
DATETIME |
product_id |
INTEGER |
quantity |
INTEGER |
products table
| Column | Type |
|---|---|
id |
INTEGER |
name |
VARCHAR |
price |
FLOAT |
Output:
| Column | Type |
|---|---|
month |
INTEGER |
month_over_month |
FLOAT |
.
.
.
.
.
.
.
.
.
Comments