Nhibernate简单自连接

发布于 2024-12-13 01:43:28 字数 503 浏览 1 评论 0原文

我有一个包含这些字段的表:

ID (Primary key)
Name 
Some more data fields

我想编写一个查询,给定名称将为我提供 ID 大于具有该名称的行的所有行。

(是的,我知道这个名字不是唯一的......在系统中是。)

我想要类似的东西:

select *
From SomeTable as x
WHERE x.ID> (Select ID from SomeTable as y where y.Name LIKE :param)

或者:

SELECT x
FROM SomeTable as x
JOIN SomeTable as y ON x.ID > Y.ID
WHERE Y.Name LIKE :Param

当然我想要自连接,而不是子查询。


顺便提一句。 标准也...

I have a table with these fields:

ID (Primary key)
Name 
Some more data fields

I want to write a query that given a Name will give me all the rows with ID's bigger then the row with that name.

(Yes yes I know the name is not unique... in the system is.)

I want something like:

select *
From SomeTable as x
WHERE x.ID> (Select ID from SomeTable as y where y.Name LIKE :param)

or:

SELECT x
FROM SomeTable as x
JOIN SomeTable as y ON x.ID > Y.ID
WHERE Y.Name LIKE :Param

Of course I want the self join, and not the sub query.


BTW.
Criteria goes too...

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

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

发布评论

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

评论(1

長街聽風 2024-12-20 01:43:28

您将无法通过 HQL 中的联接来完成此操作。

但是这个 HQL 查询是可以的:

select f from Foo f where f.id > (select f2.id from Foo f2 where f2.name = :name)

如果子查询可能返回多个 ID,您也可以使用

select f from Foo f where f.id > all (select f2.id from Foo f2 where f2.name = :name)

You won't be able to do it with a join in HQL.

But this HQL query is OK:

select f from Foo f where f.id > (select f2.id from Foo f2 where f2.name = :name)

If the subselect might return several IDs, you may also use

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