2017-07-19 48 views
0

我需要生成hql查詢。我的表結構如下
給定-----一對多------>乙如何形成一對多關係的HQL查詢並將其分組爲一對多

和我的Oracle數據庫查詢

select a.CONF_NUMBER,to_char(max(b.RECEIVE_DATE), 'YYYY-MM-DD hh24:mi:ss') 
from A a, B b 
where b.RECEIVE_DATE >= to_date('2012-06-07 13:20:28','YYYY-MM-DD hh24:mi:ss') 
group by a.CONF_NUMBER 

在這裏我感到困惑的事實,如何最大(b.RECEIVE_DATE)可應用於 困惑在HQL

+0

更多信息不要忘了接受/給予好評,幫助你的答案... – Cepr0

回答

1

子查詢是如何工作的嘗試是這樣的:

DTO

public interface NumAndDate { 
    String getNumber(); 
    Date getDate(); 
} 

public interface ARepository extends JpaRepository<A, Long> { 

    @Query("select a.confNumber as number, max(b.receiveDate) as date from A a join a.b b where b.receiveDate >= ?1 group by a.confNumber") 
    List<NumAndDate> getDataByDate(Date date); 
} 

JPQL Language Reference