使用CASE条件和连接语句从多个视图的本机SQL查询形成JPQL查询

时间:2012-12-12 05:43:35

标签: jpa jpql

请使用CASE条件和连接语句帮助转换多个视图的本机查询ti JPQL查询。表c1和c3是视图。我正在尝试从c1获取当前和待定信息。 请找到下面提到的查询

    SELECT c3.eqip_id  AS EQIP_ID, 
           CASE  WHEN c1.inst_ts IS NULL OR c1.sent_ts > c1.inst_ts THEN c1.ver_nm  END  AS PEND, 
           CASE  WHEN c1.sent_ts IS NULL OR c1.sent_ts > c1.inst_ts THEN c1.ver_nm  END  AS CURRENT, 
           c1.trm_ver_hist_id AS TRM_VER_HIST_ID 
    FROM   trm_ver_hist_vw c1 
           JOIN(SELECT Max(trm_ver_hist_id) AS TRM_VER_HIST_ID, dvc_id, status 
                FROM   trm_ver_hist_vw 
                WHERE  ver_typ_id = 1  AND status IN( 'C', 'P' ) 
                GROUP  BY dvc_id, status) c2 
             ON c1.trm_ver_hist_id = c2.trm_ver_hist_id 
           JOIN trm_dtl_vw c3  ON c1.dvc_id = c3.trm_id 
    WHERE  c3.co_actv_ind = 'Y'  AND c3.mach_hdwr_asscn_ind = 'Y' AND pin = 'ABC'   

有人可以帮我在JPA / JPQL中进行此查询吗?

1 个答案:

答案 0 :(得分:0)

它似乎非常复杂且数据具体。我建议使用本机SQL查询。

JPA规范不允许在FROM子句中进行选择,尽管EclipseLink确实对此有一些支持。

http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/JPQL#Sub-selects_in_FROM_clause