Created
December 16, 2020 10:41
-
-
Save romain9292/b562f68624c91ac27df80ce4006641fa to your computer and use it in GitHub Desktop.
[Growth rate using SQL in BigQuery - Part 2] Computing a month over month revenue growth rate #SQL #BigQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH | |
revenue_over_month AS ( | |
SELECT | |
DATE_TRUNC(PARSE_DATE('%Y%m%d', | |
date),MONTH) AS months, | |
ROUND(SUM(totals.totalTransactionRevenue)/10e+6,2) AS revenue, | |
FROM | |
`bigquery-public-data.google_analytics_sample.ga_sessions_20*` | |
GROUP BY | |
1) | |
-- Main Query | |
SELECT | |
*, | |
LAG(revenue) OVER(ORDER BY months ASC) AS last_month_revenue | |
FROM | |
revenue_over_month | |
ORDER BY | |
months ASC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment