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

186
Views
How do i count a data that includes another data in sequelize?

So I was trying to get a record about car dealers who successfully sold a specific car, sorted from how much the dealer successfully sold that car so the dealer that successfully sold the most of that specific car will appear first. The problem is that in the end I also need to group the car id, which makes the counting inaccurate. Can anyone please help me solve this problem where I can just get the record without needing to group the car id as well?

Here is my code:

const data = await models.Car.findAll({
      paranoid: false,
      attributes: [[Sequelize.fn('COUNT', Sequelize.col('userId')), 'carsCount'], 'userId'],
      where: { brandId, groupModelId, status: 2 },
      include: [
        {
          model: models.User,
          as: 'user',
          required: true,
          duplicating: false,
          attributes: ['name', 'phone', 'email'],
          include: [
            {
              model: models.UserAddress,
              as: 'userAddress'
            }
          ]
        }
      ],
      group: ['userId', 'user.id'],
      offset,
      limit
    })

Thank you in advance and sorry if my English is not perfect

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!