Aggregates as window functions
Aggregate functions can be used as window functions as well. For instance, let's use the SUM()
aggregate function as a window function for computing the sum of the successfully transferred amount per customer until each caching date, as illustrated in the following screenshot:
The jOOQ query can be expressed like this:
ctx.select(BANK_TRANSACTION.CUSTOMER_NUMBER, BANK_TRANSACTION.CACHING_DATE, BANK_TRANSACTION.TRANSFER_AMOUNT, BANK_TRANSACTION.STATUS, sum(BANK_TRANSACTION.TRANSFER_AMOUNT).over() .partitionBy(BANK_TRANSACTION.CUSTOMER_NUMBER) .orderBy(BANK_TRANSACTION.CACHING_DATE) .rowsBetweenUnboundedPreceding().andCurrentRow().as("result")) .from(BANK_TRANSACTION) .where(BANK_TRANSACTION.STATUS.eq("...