gpt4 book ai didi

java - 在 QueryDSL 分组转换器中计数

转载 作者:搜寻专家 更新时间:2023-10-31 19:55:48 25 4
gpt4 key购买 nike

在QueryDSL中使用groupby处理是否可以得到聚合结果的计数?我有以下查询:

query.from(catalog)
.innerJoin(qe).on(catalog.id.eq(qe.itemId))
.innerJoin(enterprise).on(enterprise.id.eq(qe.enterpriseId))

.leftJoin(catalogPerson).on(catalogPerson.catalogId.eq(catalog.id))

.where(catalog.deletionDate.isNull(), qe.enterpriseId.eq(org) )

.orderBy(catalog.creationDate.desc())

.limit(limit)
.offset(offset)

.transform(groupBy(catalog.id).as(Projections.constructor(Catalog.class,
catalog.id,
catalog.name,
catalog.code,
// //GET THE NUMBER OF CATALOG PERSONS'
)));

我想统计属于某个目录的人数。

谢谢

最佳答案

如果您不需要任何子记录,则无需像这样通过转换来表达查询(仅草图)

query.from(catalog)
.innerJoin(qe).on(catalog.id.eq(qe.itemId))
.innerJoin(enterprise).on(enterprise.id.eq(qe.enterpriseId))
.leftJoin(catalogPerson).on(catalogPerson.catalogId.eq(catalog.id))
.where(catalog.deletionDate.isNull(), qe.enterpriseId.eq(org))
.orderBy(catalog.creationDate.desc())
.limit(limit)
.offset(offset)
.groupBy(catalog.id)
.list(Projections.constructor(Catalog.class,
catalog.id,
catalog.name,
catalog.code,
catalogPerson.count()));

如果您需要聚合单个结果行,则按转换分组很有用。

关于java - 在 QueryDSL 分组转换器中计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19136769/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com