如何使用 ORM 编写这个查询?
SELECT p.id,
p.name,
COUNT(c.id) counter
FROM Posts p
LEFT JOIN Comments c
ON c.post_id = p.id
WHERE p.rating > 100
GROUP BY p.id
HAVING counter > 10
ORDER BY counter DESC
LIMIT 5
尝试这个:
Post.findAll({
where: {rating: {gt: 100}},
include: [Comments],
having: ['COUNT(?) >= ?', '`comment`.`id`', 10]
})
Read 我的研究通过这个问题。
i use [电子邮件受保护]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)