如何在JPA JPQL中编写这个SQL select?

时间:2014-01-29 11:49:56

标签: java sql jpa jpql

我有一个,称之为 REI_BODY ,我有另一个,称之为 REI_AMT_INFO 。我在 oracle pl / sql 中选择了

  

选择         *,

  (SELECT AMT    FROM REI_AMT_INFO I WHERE I.REI_ID=T.REI_ID AND AMT_TYPE_CD = '01') AMT_01,
  (SELECT AMT    FROM REI_AMT_INFO I WHERE I.REI_ID=T.REI_ID AND AMT_TYPE_CD = '02') AMT_02,

  (SELECT SGN_CD FROM REI_AMT_INFO I WHERE I.REI_ID=T.REI_ID AND AMT_TYPE_CD = '01') SGN_01,
  (SELECT SGN_CD FROM REI_AMT_INFO I WHERE I.REI_ID=T.REI_ID AND AMT_TYPE_CD = '02') SGN_02,

FROM REI_BODY T

这是REI_AMT_INFO表, 没有外键!

REI_ID (Number);
AMT_TYPE_CD (Varchar);
AMT (Number);
SGN_CD (Varchar);

我必须用JPA JPQL语言创建这个选择。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

@NamedQuery(
    name="REI_BODY",
    query="SELECT *,

  (SELECT AMT    FROM REI_AMT_INFO I WHERE I.REI_ID=T.REI_ID AND AMT_TYPE_CD = '01') AMT_01,
  (SELECT AMT    FROM REI_AMT_INFO I WHERE I.REI_ID=T.REI_ID AND AMT_TYPE_CD = '02') AMT_02,

  (SELECT SGN_CD FROM REI_AMT_INFO I WHERE I.REI_ID=T.REI_ID AND AMT_TYPE_CD = '01') SGN_01,
  (SELECT SGN_CD FROM REI_AMT_INFO I WHERE I.REI_ID=T.REI_ID AND AMT_TYPE_CD = '02') SGN_02,

FROM REI_BODY T"
)

CHECK THE LINK