Skip to main content

Ordered Subsets with Rolling Sums

  • Chapter
  • First Online:
Practical Oracle SQL
  • 1386 Accesses

Abstract

One of the most useful features of analytic functions is the flexibility of the window clause, enabling aggregation of particular subsets of the data within a specific order. A classic subset that can be used for many purposes is the set of data from the beginning until the current row – if, for example, the sum aggregate function is used on that subset, you get an accumulated sum or rolling sum or running total (many names for the same thing). The use cases are plenty; many financial reports need running totals. But a different and extremely practical use case involves a slight variation of the running total, using the sum of all the previous rows to keep selecting rows until a just sufficiently large subset to cover the necessary sum has been reached. This can, for example, be used to build a FIFO warehouse picking list in a single SQL statement.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2020 Kim Berg Hansen

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Berg Hansen, K. (2020). Ordered Subsets with Rolling Sums. In: Practical Oracle SQL. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-5617-6_13

Download citation

Publish with us

Policies and ethics