This is not what the query in the post is doing.
You are counting all stars of all repos, they are counting stars of one (parameterized) repo id.
You are counting all stars of all repos, they are counting stars of one (parameterized) repo id.
Where r.id = :repo
and you will have the same thing.