连接所需的 HQL 路径(连接同一个表时)

发布于 2024-12-02 04:28:10 字数 674 浏览 1 评论 0原文

我正在尝试获取两个不同设备的测量对,并在相同的时间戳上连接。在 SQL 中,这按预期工作:

select
  leftItem.Timestamp, leftItem.Value, rightItem.Value
from
  DataTable leftItem
  inner join DataTable rightItem
  on leftItem.Timestamp = rightItem.Timestamp
where
  leftItem.Device = 1 and rightItem.Device = 2

但如果我尝试将其转换为 HQL:

select
  left, right 
from
  DataTable as left 
  inner join DataTable as right
  on left.Timestamp = right.Timestamp
where
  left.Device = 1 and right.Device = 2

我得到一个 NHibernate.Hql.Ast.ANTLR.SemanticException:

Path expected for join!

How do I specify a “path” to the same table ?

I am trying to get pairs of measurement for two different devices, joined on equal Timestamps. In SQL, this works as expected:

select
  leftItem.Timestamp, leftItem.Value, rightItem.Value
from
  DataTable leftItem
  inner join DataTable rightItem
  on leftItem.Timestamp = rightItem.Timestamp
where
  leftItem.Device = 1 and rightItem.Device = 2

But if I try to convert it to HQL:

select
  left, right 
from
  DataTable as left 
  inner join DataTable as right
  on left.Timestamp = right.Timestamp
where
  left.Device = 1 and right.Device = 2

I get a NHibernate.Hql.Ast.ANTLR.SemanticException:

Path expected for join!

How do I specify a "path" to the same table?

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

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

发布评论

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

评论(1

像极了他 2024-12-09 04:28:10

在 HQL 中,连接只能在实体之间的关联上完成。如果您想要连接其他内容,唯一的可能性是在 where 子句中进行连接:

select left, right 
from
  DataTable as left, DataTable as right
where
  left.Timestamp = right.Timestamp
  and left.Device = 1 
  and right.Device = 2

In HQL, joins can only be done on associations between entities. If you want a join on something else, the only possibility is to make the join in the where clause:

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