我想显示按服务名称分组的历史记录表中的记录数
请注意,两个表历史记录和服务之间没有关系,历史记录将活动独立于其他表存储
我测试了这个sql查询,它返回了预期的结果:
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'....二元运算符的右侧操作数为null ....子树的意外结束
答案 0 :(得分: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"
);