Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
Query to get most popular musician with an aggregated field sum

I have the following database schema:

model Music {
  id        Int      @id @default(autoincrement())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  title     String   @db.VarChar(255)
  duration  Int
  playbacks Int
  artist    Musician?  @relation(fields: [musicianId], references: [id])
  artistId  Int?
}

model Musician {
  id        Int      @id @default(autoincrement())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  name      String?
  musics    Music[]
  albums    Album[]
}

And I have to return a 3 most popular musicians with an aggregated field totalPlaybacks in each one.

Is this possible to do this using findMany in prisma?

This is my controller:

exports.getTopThree = (req, res) => {
  prisma.artist
    .findMany({
       //should the query be there
    })
    .then((data) => {
      console.log(data);
      res.send({ data });
    })
    .catch((err) => {
      res.status(500).send({
        message: err.message || "Some error occurred while retrieving artists.",
      });
    });
};

Could someone help me on this problem?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!