Nested Aggregate Functions Postgresql Jdbc