querydsl变压器组按计数 [英] querydsl transformer group by count

查看:155
本文介绍了querydsl变压器组按计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让查询(QueryDSL)工作,这让我计算了不同的类别。
例如,我想要实现的目标:

I am stuck trying to get a query (QueryDSL) to work that gives me a count of distinct categories. For example, what I am trying to achieve:

categoryA -> 10 entries
categoryB -> 20 entries

这是我到目前为止:

query().from(application)
            .transform(groupBy(application.category).as(list(application)));

然而,这给了我每个类别所有整个条目的列表,我只想得到一个算上这个。

However, this gives me for each category a list of all whole entries, I just want to get a count of this.

我试过搞乱 count(),但没有运气。

I tried messing around with count() but no luck.

有谁知道怎么做?

推荐答案

变换组合groupBy用于构造树结构超出平坦的结果集。您需要的内容可以更容易表达为

transform combined groupBy is meant to construct tree structures out of flat result sets. What you need can be easier expressed as

query.from(application)
     .groupBy(application.category)
     .list(application.category, application.category.count())

这篇关于querydsl变压器组按计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆