• Please can we see the table that contains the grouping information?

    I think the best way will be to add up and and number the groups in a CTE, then do the division in the main part of the query.

    John