Many systems support user-defined aggregates[0][1]
[0] https://www.postgresql.org/docs/current/sql-createaggregate....
[1] https://docs.oracle.com/en/database/oracle/oracle-database/2...