微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Spring Data JPA UNION 本机查询

如何解决Spring Data JPA UNION 本机查询

我需要从主表中获取历史记录表中的所有数据和非匹配数据。使用 UNION 查询能够获取两个表数据。

但问题是历史表 10 个子表和主表还有 10 个子表。无法获取子表数据。 我还使用连接查询获取子表数据,但在点击它保留的 swager 时无法获取子表数据 正在加载但无法获取。也没有收到任何错误

任何帮助将不胜感激。

@Query(nativeQuery = true,value= "SELECT                                                                                                          "            
                           + " a.customerid AS customerID,"
                           + " a.stepid AS stepID,"
                           + "a.finance_percentage AS financePercentage,"
                           + "a.finance_tenor_days AS financeTenor,"
                           + "a.finance_type AS financeType,"
                           + "a.institution AS institution,"
                           etc...............                                      "
                          + "a.customer_name AS customerName                                                                                        "
                          +  "FROM  txrh_bcaterms a"
                          + " INNER JOIN txrh_bcaterms_allowed_finance_currencies b ON b.institution = a.institution AND b.customerid=a.customerid AND b.tx_booking_location=a.tx_booking_location AND b.finance_type=a.finance_type AND b.limit_groupid=a.limit_groupid             "
                                            etc...........
                          
                          + " INNER JOIN txrh_bcaterms_allowed_proforma_invoice_documents j ON j.institution = a.institution  AND j.customerid=a.customerid AND j.tx_booking_location=a.tx_booking_location AND b.finance_type=a.finance_type AND b.limit_groupid=a.limit_groupid    "
                          + " INNER JOIN txrh_bcaterms_allowed_payments_third_parties k ON k.institution = a.institution  AND k.customerid=a.customerid AND k.tx_booking_location=a.tx_booking_location   AND b.finance_type=a.finance_type AND b.limit_groupid=a.limit_groupid      "
                          + "where step_status IN ('SAV','REJ') " + " AND a.institution = :institution                        "
                          + " AND (COALESCE(:txBookingLocation,null) is null or (a.tx_booking_location IN :txBookingLocation))                     "
                          + "UNION                                                                                                                           "

                + "SELECT                                                                                                                          "
                           + "a.customerid AS customerID,"
                           + "null AS stepID,"
                           +" a.finance_tenor_days AS financeTenor,"
                       
                           + "a.institution AS institution,"
                           + "a.limit_groupid AS limitGroupID,"
                           + "null AS checkerID,"
                                  etc..........                                   "
                           + "a.customer_name AS customerName                                                                                        "
                           + "FROM  txrm_bcaterms a "
                           + " INNER JOIN txrm_bcaterms_allowed_finance_currencies b ON b.institution = a.institution AND b.customerid=a.customerid  AND b.tx_booking_location=a.tx_booking_location  AND b.finance_type=a.finance_type AND b.limit_groupid=a.limit_groupid            "
                                 etc...............
                           + " INNER JOIN txrm_bcaterms_allowed_proforma_invoice_documents j ON j.institution = a.institution  AND j.customerid=a.customerid AND j.tx_booking_location=a.tx_booking_location AND b.finance_type=a.finance_type AND b.limit_groupid=a.limit_groupid   "
                           + " INNER JOIN txrm_bcaterms_allowed_payments_third_parties k ON k.institution = a.institution  AND k.customerid=a.customerid AND k.tx_booking_location=a.tx_booking_location   AND b.finance_type=a.finance_type AND b.limit_groupid=a.limit_groupid     "
                           + "where (a.institution,a.tx_booking_location) NOT IN                                                  "  
                           + " (select a.institution,a.tx_booking_location from txrh_bcaterms a  where step_status IN ('SAV','REJ','PNR') "
                           + " AND (COALESCE(:txBookingLocation,null) is null or ( a.tx_booking_location IN :txBookingLocation))"
                           + " AND a.institution = :institution ) "
                           + " AND a.institution = :institution "
                           + " AND (COALESCE(:txBookingLocation,null) is null OR a.tx_booking_location IN :txBookingLocation)",countQuery = " SELECT count(*) FROM ("
                                + " SELECT institution AS institution,tx_booking_location AS txBookingLocation"
                                + " FROM txrh_bcaterms where step_status IN ('SAV','REJ') "
                                + " AND institution = :institution "
                                + " AND (COALESCE(:txBookingLocation,null) is null or (tx_booking_location IN :txBookingLocation)) "
                                + " UNION " + " SELECT institution AS institution,tx_booking_location AS txBookingLocation "
                                + " FROM txrm_bcaterms   where (institution,tx_booking_location) NOT IN "
                                + " (select institution,tx_booking_location from txrh_bcaterms  where step_status IN ('SAV','PNR') "
                                + " AND (COALESCE(:txBookingLocation,null) is null or  tx_booking_location IN :txBookingLocation)"
                                + " AND institution = :institution ) "
                                + " AND institution = :institution "
                                + "AND (COALESCE(:txBookingLocation,null) is null OR tx_booking_location IN :txBookingLocation)"
                                + ")as cnt")                                                                                                                                                                                                                    
    Page<ITXBCATermsHistoryBookingLocationAndInstitutionDTO> historyAndMaster(
            @Param("institution") String institution,@Param("txBookingLocation")  List<String> txBookingLocation,Pageable page);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。