Aggregate Group Count + Order by


Is there a way to order an aggregate group by counter ?

For example, this query to count how many people per city:
match $p isa person; ($p, place:$l); aggregate group $l count;

how could I order it from the most populated city to the least ?

Also, is there any way to order it by name ?


Unfortunately, graql does not allow you to order the group by count.

However, you can use degree query to get the all group sizes.

compute degrees of city in RelationTypeBetweenPersonAndCity;

Just replace RelationTypeBetweenPersonAndCity with the relation type you want to use.