HQL:如何将新的对象构造函数与'distinct'和'order by'

问题描述 投票:0回答:1

我需要使用HQL对象构造器功能,我还需要对特定的列使用distinct关键字,最后我要按如下方式使用order:

@Query("select distinct (a.id) new com.ResultBean " +
        "(a.id, a.title, a.price, b.status) from EntityA a " +
        "LEFT JOIN EntityB b with (a.id=b.a.id ) order by a.id,b.id")

这可能吗?

sql jpa hql
1个回答
0
投票

您可以简单地使用group by,以便元素是不同的:

@Query("select new com.ResultBean" +
       "(a.id, a.title, a.price, b.status) from EntityA a " +
       "LEFT JOIN EntityB b with (a.id=b.a.id ) group by a.id, a.title, a.price, b.status order by a.id,b.id")
List<ResultBean> getResultBean();
© www.soinside.com 2019 - 2024. All rights reserved.