【问题标题】:How to avoid duplication and to fetch the child class records based on max value in HQL如何避免重复并根据 HQL 中的最大值获取子类记录
【发布时间】:2016-02-09 13:15:20
【问题描述】:

我目前使用的Hql查询是

from ListAssessImpl x left join fetch x.reviews r where x.site in 
(:currentSearchSite) and x.status = :status and 1=1 order by x.score
desc, x.name asc

ListAssessImpl 和评论是基于 ListAssessImpl Id 的评论中的一对多、多条记录。

如果我只能从基于 ListAssessImpl 的评论中获取最大值,我该如何修改查询。

我尝试使用 Max() ,但没有成功,我使用的是 Hibernate 3 和 spring 2.5

【问题讨论】:

    标签: mysql hibernate hql


    【解决方案1】:
    select max(r.value) from ListAssessImpl x left join x.reviews r
    where x.site in (:currentSearchSite) and x.status = :status
    

    【讨论】:

    • 如果我必须从 ListAssessImpl 及其对应的记录中获取记录怎么办?
    • 然后,只需重新调整查询以考虑所有必要的信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-18
    • 2012-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多