Nesting of aggregate functions...is not allowed

See if this helps