DQL: How to group by inside group by?

Hello Devid,

Since you’re applying groupby to country.id which is a uid predicate, you can capture and save the count in a variable and use it in a different function.

{ 
  var(func: has(users.id)) {
    users.id

    users.friends {
       ~country.friends @groupby(country.id) {
      	c as count(uid)
      }
    }
  }

  byCountry(func: uid(c), orderasc: val(c)) {
    uid
    countryCount: val(c)
  }
}

Can you check if this works for you ?