Skip to content

Instantly share code, notes, and snippets.

@alex-groshev
Created April 22, 2015 08:15
Show Gist options
  • Save alex-groshev/06b1b0c55c2eb21e5a74 to your computer and use it in GitHub Desktop.
Save alex-groshev/06b1b0c55c2eb21e5a74 to your computer and use it in GitHub Desktop.
Daily Returns / SQL Server 2012+
SELECT
Date
,Value
,CAST(ROUND(100 * (Value / LAG(Value, 1, Value) OVER (ORDER BY Date) - 1), 2) AS NUMERIC(16, 2)) AS 'Return'
FROM Totals
ORDER BY Date;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment