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 (将#修改为@)