Search code examples
javascripttypescripttypeorm

Convert my SQL into Typeorm query builder


SELECT DATE(OrderDate) AS date, COUNT(OrderId), ShipperID
FROM [Orders]
GROUP BY DATE(OrderDate), ShipperID
Order By Date(OrderDate) desc

I can't pass two parameters to groupBy() method in queryBuilder. Is there other way around?


Solution

  • getRepository(Orders)
      .createQueryBuilder('o')
      .select(['Date(o.OrderDate)','o.ShipperID', 'Count(o.OrderID)']) 
      .groupBy('Date(o.OrderDate), o.ShipperID')
      .orderBy('Date(o.OrderDate)', 'DESC')
      .getRawMany()