【问题标题】:I am trying to write a jpa query for subqueries我正在尝试为子查询编写 jpa 查询
【发布时间】:2015-08-08 01:12:37
【问题描述】:

我正在尝试为子查询编写 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 原生查询,但现在有一个可变周期。

【问题讨论】:

    标签: jpa jpql


    【解决方案1】:

    我使用类型化查询并为内部查询创建了一个列表。

        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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-11
      • 2021-05-01
      • 1970-01-01
      • 2020-06-09
      • 1970-01-01
      • 2011-03-22
      • 1970-01-01
      • 2021-03-23
      相关资源
      最近更新 更多