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

238
Views
Find the sum of a Column with group by and Joins in one Query using Sequelize ORM

Hi Hope you all are doing well I am using Sequelize ORM in node js I have to sum the final price of orders of one day and display the data so i want to find the some of final prices group by "createdAt" field but not able to use group by "createdAt" as i have made joins with other tables in the same query

Order.findAll(
        {
            logging:console.log,
            subQuery:false,
            include:[
                { 
                    model: fulfillments,
                    required:true,
                    attributes:['fulfillment_status_id' , 'order_id'],
                    include:{
                        model:fulfillmentStatus,
                        where:{
                             delivery_status_name:fulfillmentStatusEnum.completed
                        }
                    }
                }
            ],
            attributes:['final_price', 'createdAt'],
        }
    )

the results i got from the above query was

SELECT "Order"."id", "Order"."final_price", "Order"."createdAt", "fulfillments"."id" AS "fulfillments.id", "fulfillments"."fulfillment_status_id" AS "fulfillments.fulfillment_status_id", "fulfillments"."order_id" AS "fulfillments.order_id", "fulfillments->fulfillmentStatus"."id" AS "fulfillments.fulfillmentStatus.id", "fulfillments->fulfillmentStatus"."delivery_status_name" AS "fulfillments.fulfillmentStatus.delivery_status_name", "fulfillments->fulfillmentStatus"."createdAt" AS "fulfillments.fulfillmentStatus.createdAt", "fulfillments->fulfillmentStatus"."updatedAt" AS "fulfillments.fulfillmentStatus.updatedAt" FROM "Orders" AS "Order" INNER JOIN "fulfillments" AS "fulfillments" ON "Order"."id" = "fulfillments"."order_id" INNER JOIN "fulfillmentStatuses" AS "fulfillments->fulfillmentStatus" ON "fulfillments"."fulfillment_status_id" = "fulfillments->fulfillmentStatus"."id" AND "fulfillments->fulfillmentStatus"."delivery_status_name" = 'completed';

but i want to acive the query mentioned blow:

select sum(final_price) , "Orders"."createdAt" from "Orders" INNER JOIN fulfillments on fulfillments.order_id = "Orders".id INNER JOIN "fulfillmentStatuses" on fulfillments.fulfillment_status_id = "fulfillmentStatuses"."id" where "fulfillmentStatuses".delivery_status_name = 'completed' GROUP BY "Orders"."createdAt"

can any one help?

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!