如何在 bean 类中使用 groupBy

Posted

技术标签:

【中文标题】如何在 bean 类中使用 groupBy【英文标题】:How to use groupBy in bean class 【发布时间】:2020-06-29 07:03:54 【问题描述】:

我有这段代码,但是在运行时我遇到了类似的错误...

找不到符号 符号:方法 groupBy(java.lang.String) 位置:接口 com.avaje.ebean.ExpressionList

    public static List<ClusterResources> getClusterLeaderByEmpId(int cluster_id) 
        List<ClusterResources> clusterLeaders = Ebean.find(ClusterResources.class)
                .where()
                .eq("cluster_id", cluster_id)
                .groupBy("cluster_leader")
                .findList();
            if (clusterLeaders == null)
                clusterLeaders = new ArrayList<>();
        return clusterLeaders;
    

【问题讨论】:

【参考方案1】:

没有看到你的模型 ClusterResources 有点难以知道你想要实现什么,但 Ebean 通常会在需要时自动添加“group by”,例如如果您选择需要分组的内容:

.select("cluster_leader, MAX(cluster_value)")

查看以下链接: Ebean aggregation 和 Ebean select

【讨论】:

以上是关于如何在 bean 类中使用 groupBy的主要内容,如果未能解决你的问题,请参考以下文章

如何在 pandas 中使用过滤条件和 groupby

如何在循环中使用 groupby() 函数?

如何在datatable中使用groupby进行分组统计

如何在 Power BI 中使用 GROUPBY 函数?

如何在 Pyspark 中使用 groupby 和数组元素?

如何在 Laravel 的 hasMany 关系中使用 groupBy