我正在尝试创建 QueryBuilder 查询,但一直失败。我需要这样写查询:
SELECT userId, COUNT(*) votes from uservotes WHERE sessionId = ? GROUP BY userId
但是使用 QueryBuilder 我所做的一切并以某种方式工作,它就是这个变体。
.createQueryBuilder('uservotes')
.select([
'uservotes.userId', 'userId',
])
.where({ sessionId: sessionId })
.groupBy('userId')
.getMany();
将非常感谢帮助
你可以这样使用
const countByUserVotes = await Uservotes.createQueryBuilder()
.select(['userId', 'count(*) as count'])
.where({ sessionId: sessionId })
.groupBy('userId')
.getRawMany();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句