You can simply use nested query. Let's assume your inner query is what you have made so far, and it is returning
type,
uid and
count fields.
select type, count(*) from
()
group by type
Or, if you want to summarize the counted values, use:
select type, sum("count") from
()
group by type