A B A_B
----- ----- ------
id id A_id
name time_stamp B_id
desc
A B
----- -----
id id
name time_stamp
[B] desc
我正在尝试创建一个HQL查询,它将拉出所有A,其中B的time_stamp是最新的,如果desc是'Done',则只返回该行。这是我现在拥有的:
select a from A a
inner join a.B b
where b.time_stamp in (
select max(selectedB.time_stamp) from B selectedB
where selectedB.id = b.id)
and b.desc = 'Done'
这似乎不起作用。它似乎只尊重desc而不关心时间选择。有什么想法吗?