我有一个下表:
create table MyData
(
id bigserial primary key,
registered timestamp not null,
deviceID int not null,
someData int,
-- a bunch of other stuff
);
我也有一个deviceIDs 列表。此列表中的每个deviceId条目都有一堆MyData具有不同registered时间戳的条目。
我需要的是从具有最新使用 JPA 查询的条目中获取someData每个条目。deviceIdtimestamp
当然,我可以编写一个查询来获取单个所需的数据deviceId,例如
SELECT d.someData from MyData d WHERE d.deviceID =:dev_id ORDER BY registered DESC
添加,为所有s.setMaxResults(1)循环它。deviceID如何将其放入单个查询中?