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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2020 Kim Berg Hansen
About this chapter
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
DOI: https://doi.org/10.1007/978-1-4842-5617-6_13
Published:
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4842-5616-9
Online ISBN: 978-1-4842-5617-6
eBook Packages: Professional and Applied ComputingProfessional and Applied Computing (R0)Apress Access Books