将 HQL 查询转换为 criteria api

发布于 2024-09-25 10:20:02 字数 287 浏览 1 评论 0原文

我想知道是否可以将此 HQL 查询转换为标准 api 查询。

select s1 
from Student
where 
     (
        select max(s2.Score)
        from Student
        where s1.Id = s2.Id
     )
      = 10

(选择最高分数等于 10 的学生)

由于“s1.Id = s2.Is”条件,我不知道是否可以使用独立标准

感谢任何可以帮助我的人

I'm wondering if is possible to convert this HQL query into a criteria api query.

select s1 
from Student
where 
     (
        select max(s2.Score)
        from Student
        where s1.Id = s2.Id
     )
      = 10

(selects the students that have their max score value equal to 10)

I don't know if I could use a detached criteria because of the 's1.Id = s2.Is' condition

Thanx for anyone who can help me

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

予囚 2024-10-02 10:20:02

她去了,

var subquery = Session.CreateCriteria<Student>()
    .Add(Restrictions.EqProperty("Id", "s1.Id"))
    .SetProjection(Projections.Max("Score"));

var results = Session.CreateCriteria<Student>("s1")
    .Add(Subqueries.Eq(10, subquery))
    .List<Patient>();

但我不确定原始查询是否正确,因为如果 Id 是主键,子查询应该始终返回 1 行

her goes

var subquery = Session.CreateCriteria<Student>()
    .Add(Restrictions.EqProperty("Id", "s1.Id"))
    .SetProjection(Projections.Max("Score"));

var results = Session.CreateCriteria<Student>("s1")
    .Add(Subqueries.Eq(10, subquery))
    .List<Patient>();

but i'm not sure if the original query is correct because the subquery should always return 1 row if Id is the primary key

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文