Tag: sum()

  • Calculate a Running Total in SQL Server

    Let’s imagine a scenario where I have a table that contains a numeric value. When I select the data from this table I want to add another column that contains the running total of all the previous numeric values added together. By leveraging SQL servers two functions: SUM() and OVER() this can be accomplished.

    (more…)

  • Understanding group bys

    Yesterday, at work, it occurred to me, not for the first time, that something that comes so easily to me, does not to others.  I had tasked someone with, what seemed a simple task, to retrieve a list of users who have reached minimum payout.

    The payouts were stored in a separate table from the users and users could have multiple payment records prior to reaching payout, thus we would need to use a SUM() on the amount.  Because we also required other data, we need to use a group by to properly sum the amounts a user has.

    The task was handed back to me several hours later to review, it was quite evident that the main concept was “grasped”, but the understanding of group bys was not. (more…)