7 votes

Modern SQL Window Function Questions

3 comments

  1. unknown user
    Link
    An interesting SQL window functions quiz I have found recently.

    An interesting SQL window functions quiz I have found recently.

    2 votes
  2. nic
    Link
    running averages are very interesting, thanks.

    running averages are very interesting, thanks.

    2 votes
  3. [2]
    Comment deleted by author
    Link
    1. Emerald_Knight
      Link Parent
      I'm not as familiar with SQL aggregation, but if it supports multiple stages of operations then I could see there being plenty of practical applications when applied to groups. An example would be...

      I'm not as familiar with SQL aggregation, but if it supports multiple stages of operations then I could see there being plenty of practical applications when applied to groups.

      An example would be first grouping rows by month, then subtracting the total of the previous month from the total of the current month in order to obtain a series of deltas. This data could be useful for telling you how much of some metric you've lost or gained over each month. A subsequent stage could then filter by negative deltas to show only losses. A practical concrete example might be telling you which quarters your sales dipped in, so you can examine the causes of profit loss.

      Use cases can be difficult to come up with, but generally if you need to compare X number of results relative to the current one, then preceding and following are likely the tools you'll want to use.

      1 vote