Trying to get the average of a count resultset
You just can put your query as a subquery: SELECT avg(count) FROM ( SELECT COUNT (*) AS Count FROM Table T WHERE T.Update_time = (SELECT MAX (B.Update_time ) FROM Table B WHERE (B.Id = T.Id)) GROUP BY T.Grouping ) as counts Edit: I think this should be the same: SELECT count(*) / count(distinct T.Grouping) FROM … Read more