Tuesday 23 October 2018

Need help with sequelize query

I am trying to execute this querySELECT name, avg(distance) as distanceAvg FROM table_name group by name; I am able to execute the query without the avg() aggregate as :Model.findAll({ attributes: ['name','distance'], group: 'name', raw: true }) but adding an aggregate function gives me error that my endpoint doesn't exist.This is my code for that: Model.findAll({ attributes:['name', [sequelize.fn('AVG', sequelize.col('distance')), 'distanceAvg']] , group: 'name', raw: true }) Any help is welcome :)

Submitted October 23, 2018 at 11:59PM by CromulentEntity

No comments:

Post a Comment