2015-05-26 5 views
-2

Я пытаюсь написать JPQL-запрос для подзапросов. Запрос выглядит следующим образом.Я пытаюсь написать запрос jpa для подзапросов

select 
    fos_name, count(ALLOCATION_BUCKET) as bucket_count 
from 
    (select 
     * 
    from 
     kic.master_mis 
    where 
     ALLOCATION_DATE IN (select 
       max(ALLOCATION_DATE) 
      from 
       kic.master_mis 
      group by BILLED_ID)) 
where 
    date(ALLOCATION_DATE) Between 'starting day month -14' AND 'till the date the month completes 30 or 31 days' group by fos_name` 

Я использую собственный запрос MySQL, но теперь есть переменный период.

ответ

0

Я сделал это, используя типизированный запрос и создав список для внутреннего запроса.

TypedQuery<Integer> query1; 
      query1=getEntityManager().createQuery("select max(m.misId) from MasterMis m group by m.billedId",Integer.class); 
      List<Integer> distinctRows1=query1.getResultList(); 
TypedQuery<Object[]> query3; 
       query3=getEntityManager().createQuery("select m.fosName,count(m.allocationBucket),sum(m.totalOutstanding), count(m.lastDispositionCodeFOS),count(m.totalCollection), sum(m.totalCollection) from MasterMis m where m.misId IN :distinctRows1 "+"and m.allocationBucket like '%B0%' and m.allocationDate BETWEEN :startDate AND :endDate group by m.fosName",Object[].class); 
       List<Object[]> s1=query3.setParameter("distinctRows1", distinctRows1).setParameter("startDate", startDate, TemporalType.DATE).setParameter("endDate", endDate, TemporalType.DATE).getResultList(); 
Смежные вопросы