Created
September 29, 2018 23:15
-
-
Save monorkin/2560a0d611956735533c43c5f2f36b18 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
-- Replace with your SQL query | |
SELECT | |
to_date(a.date::text, 'YYYY-MM-DD') AS date, | |
a.count AS count, | |
to_char( | |
(count::float / lag(count) over (order by date) - 1) * 100, | |
'FM999999999.0%' | |
) AS percent_growth | |
FROM ( | |
SELECT | |
date_trunc('month', posts.created_at) AS date, | |
COUNT(1) AS count | |
FROM posts | |
GROUP BY date | |
) AS a | |
ORDER BY a.date |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment