如何执行一个sql查询,它在sequelizejs中为它的count()列连接另一个表

时间:2014-09-25 16:00:53

标签: mysql sql node.js sequelize.js

这是一个原始的SQL查询,我想知道如何在sequelizejs中执行它

SELECT users.id, count(companies.area)
FROM users
LEFT JOIN companies
ON users.id = companies.user_id

感谢

1 个答案:

答案 0 :(得分:1)

你走了:

User.findAll({
  attributes: ['id', sequelize.fn('count', sequelize.col('companies.area'))],
  include: [Company]
});