【发布时间】:2017-12-22 12:52:52
【问题描述】:
我使用带有休眠实现和 postgres 的 spring data jpa 我有两张桌子
台式机:ID、名称
表记录:id、machine_id、temp1、time_stamp
我搜索显示每台机器的最后一条记录(id、machine_id、name、temp1)
这个 sql 查询似乎可以完成这项工作
select r.*, d.*
from machine d
join record r on (d.id=r.machine_id)
left outer join record r2 on (d.id=tr2.machine_id and
(r.time_stamp<r2.time_stamp or r.time_stamp=r2.time_stamp and r.id<r2.id)
)
where r2.id is null
但我在 jpa 中搜索这样做
【问题讨论】:
-
请明确你想要什么... JPQL 中的这个 sql?
-
它清楚地写了查询是在 sql 中......我搜索在 jpql 中写它..
标签: postgresql jpa spring-data-jpa