You usually have to include ALL the selected fields in the groupby and orderby clauses.
Anyhow, the logic of the query doesn't seem correct either. I think you probably need something like this:
count = db.ficheiros.entity.count()
db(db.ficheiros.entity==db.entity.id).select(db.ficheiros.entity, count,
groupby=db.ficheiros.entity, orderby=db.ficheiros.entity)
You can always see the SQL generated by printing to the console with
_select. For example:db(db.ficheiros.entity==db.entity.id)._select(db.ficheiros.entity, count,
groupby=db.ficheiros.entity, orderby=db.ficheiros.entity)
All the best.