2015-04-06 50 views
0

我想顯示在名字服務簡單連接語法不正常

  • 服務(代碼名)
  • 歷史(ID,密碼分組的歷史表中的記錄數,。 ...)

請注意,這兩個錶的歷史和服務之間沒有任何關係,從歷史

我已經測試過這個sql查詢的其他表獨立門店活動d返回預期的結果:

select s.name, count(*) from history c 
join service s 
on c.code=s.code 
where c.state='INITIALE' 
group by s.name 

其實,我想它寫在JPQL,我也一樣

Query query =entityManager.createQuery(" select s.name, count(*) from ServiceEntity s join" 
       + " HistoryEntity c " 
       + " where c.code=s.code and c.state='INITIALE'" 
       + " group by c.name order by c.name" 
       ); 

我得到這個錯誤路徑預期的加入! ... 無效的路徑:「c.code」 ....二元運算符的右側操作數是子樹的空....意外結束

+0

這兩個查詢使用不同的表。第一個查詢使用's​​ervice'和'history'表,而第二個查詢使用'ServiceEntity'和'HistoryEntity'表。在查詢工具(如SQL * Plus或SQL Developer)中測試第二個查詢時會發生什麼?它是否正確執行? – 2015-04-06 11:38:52

回答

0

試試這個

Query query = entityManager.createQuery("select s.name, count(s) from ServiceEntity s, HistoryEntity c " 
       + " where c.code = s.code and c.state = 'INITIALE'" 
       + " group by s.name order by s.name" 
       );