Hi, I have a structure a bit like this ```model Th...
# orm-help
t
Hi, I have a structure a bit like this
Copy code
model Thanks {
    target: string
    reason: string
}
with target being a user's name. I'm wondering how I can find the top 10 users that have the most thanks? Thank you.
1
t
You can use
Copy code
await prisma.thanks.groupBy({
     orderBy: {
        _count: {
              target:  'desc'
         }
     },
     _count: {
       target: true
     },
     by: ['target'],
     take: 10
})
The result may be what you want. Each element of that have count of thanks and userId as target.