Test aggregate functions in DB