这是一个原始的SQL查询,我想知道如何在sequelizejs中执行它
SELECT users.id, count(companies.area)
FROM users
LEFT JOIN companies
ON users.id = companies.user_id
感谢
答案 0 :(得分:1)
你走了:
User.findAll({
attributes: ['id', sequelize.fn('count', sequelize.col('companies.area'))],
include: [Company]
});