我有一个表,称之为 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语言创建这个选择。我怎么能这样做?
答案 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"
)