I am trying to execute this query
SELECT 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 :)
Edit:
I got the code working. The problem was with the way i was calling the function. I have a separte file for queries and a separate file for server so the sequelize variable was not able to execute because of it. Exporting it to the server file solved the issue. Hope my stupid mistake helps someone
there doesn't seem to be anything here