Developing SQL to get aggregates counts