I have stumbled across the below query from the internet and would like to know how I can apply it to my SQL query. I am currently using SQL Server 2012.
(total::float / lag(total) over (order by month) - 1) * 100 growth
select to_char(created_at, 'yyyy-mm') as month, count(user_id) total
group by month
order by month;
The link to this code is http://stackoverflow.com/questions/16357876/sql-query-growth-of-users-per-month-in-percentage
however it is for Postgres.
Could someone please help me translate this for MS SQL. Please note that I would need to SUM my totals for a month as an account could have multiple transactions within a single month.