How to count comment and post for each person in Post System?

I have a Post dataset, and I have a analyze problem for counting how many comment and post each person has created. Can you help me to make it ?
The schema for Post dataset is as below :

I try to write the DQL like below, but failed:

Hey wwwjljj,

I can help you. But first I gonna point out some things on your query.

1 - Group by works only with Edges (the relational ones). We don’t support Group By value for now.
2 - You should avoid using has func on root. Please, use Type() instead. That will make your query fast and reliable. Unless you have your reasons.
3 - Another option instead of has() or Type() is to use the count index on root. That is way faster than has().
4 - I think maybe you’re confusing the data structure. Because this query feels like is looking for “by creation” to find “the creator”. Is that your goal?

Please share a sample of your structure. It can have fake values. But it is important to have the same data structure you have there.



Hi MichelDiz,
Thanks for your guide, and that is useful for me.
I’ve sent you the data by message in a zip file .

Hey @wwwjljj, sorry the delay.
Please check if this query works for you.

 p1 as var(func: gt(count(~hasCreator),5), first:130) @filter(type(Person)) {
    Comments as _Comments: count(<~hasCreator>) @filter(type(Comment)) 
    Posts as _Posts: count(<~hasCreator>) @filter(type(Post)) 
    count4EachPerson(func: uid(p1)){
      Comments: val(Comments)
      Posts: val(Posts)


Great work! That is what I want. :+1:t2: :clap:t2:
Thanks very much!

1 Like