Postgresql Nested Aggregate Functions Excel