转换SQL查询以序列化
这是我的 SQL 查询,我想将此查询转换为后续查询:
SELECT
`users`.`uId`, `users`.*,
COUNT(`tasks`.`userUId`) AS 'tasksCount'
FROM
`users` AS `users`
LEFT OUTER JOIN
`tasks` AS `tasks` ON `users`.`uId` = `tasks`.`userUId`
GROUP BY
`users`.`uId`;
This is my SQL query, I want to convert this query to sequelize query:
SELECT
`users`.`uId`, `users`.*,
COUNT(`tasks`.`userUId`) AS 'tasksCount'
FROM
`users` AS `users`
LEFT OUTER JOIN
`tasks` AS `tasks` ON `users`.`uId` = `tasks`.`userUId`
GROUP BY
`users`.`uId`;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在
attributes
选项中使用Sequelize.fn
并在group
选项中指示users.id
:You can use
Sequelize.fn
in theattrubutes
option and indicateusers.id
ingroup
option: