Postgresql Nested Aggregate Functions Javatpoint Php