14.2. The PRD() Aggregate Function

If you were a math major, you would write capital sigma (Σ) for summation and capital Pi (Π) for product for the aggregate summation and aggregate product, respectively. The SUM() and SUM () PO OVER () functions are the SQL versions of the sigma. We do not have an aggregate function in SQL, but if we did the syntax for it would look something like:

PRD ([DISTINCT] <expression>)   [<window clause>]

You can create such an aggregate from the LN() natural log function and LOG10() base ten logarithm function. But you will need CASE expressions to handle some special situations.

  1. If there is a zero anywhere in the column, the answer is zero. Oh, the logarithm is not defined for zero.

  2. If the values are all positive, you ...

Get Joe Celko's Thinking in Sets: Auxiliary, Temporal, and Virtual Tables in SQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.