1

请帮助使用 CASE 条件和连接语句将本机查询转换为 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 中进行此查询?

4

1 回答 1

0

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

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

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

于 2012-12-12T15:57:55.330 回答