Postgresql Nested Aggregate Functions In Excel