Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does group by works in sequelize?

I am looking for group by queries through Sequelize and cannot seem to find any documentation.

    SELECT column, count(column)       FROM table      GROUP BY column 
like image 314
user964287 Avatar asked Mar 25 '14 06:03

user964287


People also ask

How do I sort data in Sequelize?

To set the Sequelize findAll sort order in Node. js, we can set the order property. const getStaticCompanies = () => { return Company. findAll({ where: { //... }, order: [ ['id', 'DESC'], ['name', 'ASC'], ], attributes: ['id', 'logo_version', 'logo_content_type', 'name', 'updated_at'] }); };

Does Sequelize automatically create table?

Automatically creates tables in MySQL database if they don't exist by calling await sequelize.

How does include work in Sequelize?

To wrap up, include takes an array of objects. These objects are queries of their own, essentially just Sequelize queries within our main query. Inside each include query we specify the associated model , narrow our results with where , and alias our returned rows with as .


1 Answers

issue: https://github.com/sequelize/sequelize/issues/348

User.findAll({  group: ['field'] }) 

i use [email protected]

like image 139
Sergey Karasev Avatar answered Oct 02 '22 20:10

Sergey Karasev