我正在尝试为子查询

时间:2015-05-26 11:28:27

标签: jpa jpql

我正在尝试为子查询编写JPQL查询。查询如下。

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本机查询,但现在现在有一个可变周期。

1 个答案:

答案 0 :(得分: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();
相关问题