Since SQL Server 2012 was released, the SQL Server engine supports a new class of aggregate functions they have named Analytic. You can find documentation for the Analytic.functions at https://docs.microsoft.com/en-us/sql/t-sql/functions/analytic-functions-transact-sql. What I find that is cool about these Analytic functions is that they extend beyond the existing set of aggregate functions, allowing you to build queries that you could do previously,…