这是我的数据库查询
select v.FK_EQUIPMENT, sum(fuel) as fuel,v1.END_TIME_METER
from vp_reports v ,
(select distinct FK_EQUIPMENT,END_TIME_METER
from vp_reports v
where MODIFIED_ON in (select max(MODIFIED_ON)
from vp_reports
where END_TIME_METER is not null
group by FK_EQUIPMENT )) v1
where v.FK_EQUIPMENT = v1.FK_EQUIPMENT
group by v.FK_EQUIPMENT,v1.END_TIME_METER;
我在jpa写的是相同的
@Query("select new Reports (v.fkEquipment, sum(fuel) as fuel, v1.endTimeMeter) "
+ " from Reports v , "
+ " (select distinct fkEquipment, endTimeMeter from Reports v "
+ " where modifiedOn in ( select max(modifiedOn) from Reports where endTimeMeter is not null "
+ " group by fkEquipment)) v1 "
+ " where v.fkEquipment = v1.fkEquipment "
//+ " and v.mrfId= ?1 "
//+ " and v.shift in (?2) and v.fkStatusDei= ?3 and v.assignedDate between to_date(?4, 'yyyy-mm-dd') and to_date(?5, 'yyyy-mm-dd') "
+ " GROUP BY v.fkEquipment,v1.endTimeMeter ")
List<Reports> findByMrfIdAndShiftAndFkStatusDeiAndAssignedDate(String mrfId, String shift, long fkStatusDei, String from, String to);
并低于错误 -
你能帮帮我吗?或如何将我的数据库查询转换为JPQL?引起:org.hibernate.hql.internal.ast.QuerySyntaxException: 意外令牌:(靠近第1行,第107栏[选择新报告 (v.fkEquipment,sum(fuel)as fuel,v1.endTimeMeter)from com.dei.domain.Reports v,(选择不同的fkEquipment, 来自com.dei.domain.Reports的endTimeMeter v其中的modifiedOn in( 从com.dei.domain.Reports中选择max(modifiedOn),其中endTimeMeter fkEquipment不是空组))v1其中v.fkEquipment = v1.fkEquipment GROUP BY v.fkEquipment,v1.endTimeMeter] at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:91) 在 org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:109) 在 org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:304) 在 org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:203)