【问题标题】:How to write JPA query for below SQL query如何为以下 SQL 查询编写 JPA 查询
【发布时间】:2021-05-01 13:42:02
【问题描述】:

我正在为以下 SQL 查询编写 JPA 查询。我对此很陌生。你能帮帮我吗..!!

提前谢谢你。

select distinct 
sdsmbr.MCID,sdsmbr.HCID,sdsmbr.SOR_CD,ehubsdsmbr1_.MBR_SQNC_NBR,ehubsdsmbr1_.NEW_MBR_CD, ehubsdsmbr1_.SBSCRBR_ID,ehubsdscvr3_.CVRG_EFCTV_DT,ehubsdscvr3_.CVRG_TRMNTN_DT,
ehubsdscvr3_.CVRG_STTS_CD,cntrct.CNTRCT_TYPE_CD
from
EHUB_MBR_SDS.EHUB_SDS_MBR sdsmbr
inner join
EHUB_MBR_SDS.EHUB_SDS_MBR_CNTRCT ehubsdsmbr1_
on sdsmbr.EHUB_MBR_ID=ehubsdsmbr1_.EHUB_MBR_ID
inner join
EHUB_MBR_SDS.EHUB_SDS_CNTRCT cntrct
on ehubsdsmbr1_.CNTRCT_ID=cntrct.CNTRCT_ID
inner join
EHUB_MBR_SDS.EHUB_SDS_CVRG ehubsdscvr3_
on ehubsdsmbr1_.EHUB_MBR_CNTRCT_ID=ehubsdscvr3_.EHUB_MBR_CNTRCT_ID
where sdsmbr.SOR_CD = 'test'
and ( ehubsdsmbr1_.MBR_SQNC_NBR ='test' or ehubsdsmbr1_.NEW_MBR_CD ='test')
and (sdsmbr.HCID ='test' or ehubsdsmbr1_.SBSCRBR_ID ='test');

【问题讨论】:

    标签: sql jpa spring-data-jpa


    【解决方案1】:

    我自己找到了解决方案。请在下面找到,这可能有助于编写您的查询。如果您有更好的解决方案,请提出建议。

    @Query("SELECT DISTINCT " +
                "sdsmbr.mcid,sdsmbr.hcid,sdsmbr.sorCd,ehubsdsmbr1_.mbrSqncNbr,ehubsdsmbr1_.newmbrCd,ehubsdscvr3_.cvrgEfctvDt,ehubsdscvr3_.cvrgTrmntnDt, " +
                "ehubsdscvr3_.cvrgSttsCd,cntrct.cntrctTypeCd, ehubsdsmbr1_.sbscrbrId " +
                "From EhubSdsMbr sdsmbr " +
                "JOIN " +
                "sdsmbr.ehubSdsMbrCntrcts ehubsdsmbr1_ " +
                "JOIN " +
                "ehubsdsmbr1_.ehubSdsCntrct cntrct " +
                "JOIN " +
                "ehubsdsmbr1_.ehubSdsCvrgs ehubsdscvr3_ " +
                "where sdsmbr.sorCd = ?1 " +
                "and ( ehubsdsmbr1_.mbrSqncNbr = ?2 or ehubsdsmbr1_.newmbrCd = ?3) " +
                "and ( sdsmbr.hcid = ?4 or ehubsdsmbr1_.sbscrbrId = ?5)")
    

    【讨论】:

      猜你喜欢
      • 2014-03-18
      • 2021-07-01
      • 1970-01-01
      • 2011-03-22
      • 2020-06-09
      • 2021-01-15
      • 2015-11-15
      • 2020-10-04
      • 1970-01-01
      相关资源
      最近更新 更多