我有四个表,即EdiTransaction,EdiTransactionDetail,EdiDocType和Edi997Details,其中EdiTransaction表与EdiDocType和EdiTransactionDetail有关系,但Edi997Details仅与EdiTransaction有关系,其余的则不相关(请单击下面的图片),我正在制作一个页面,其中所有EdiTransaction与对应的DocType 856/810,带有PO编号的EdiTransactionDetail及其Edi997Details。由于Edi997Details与EdiDocType和EdiTransactionDetails没有关系,所以现在我非常纠结于如何使用EdiTransaction表检索/加入Edi997Details,我能够检索除Edi997Details之外的所有内容。

php - 如何将这些表一起加入-LMLPHP

这是在EdiTransactionRepository中检索EdiTransaction的代码:

public function getAsnDetails ($poNumber,$fileName, $page = 1 , $limit = 15) {

                $em = $this->getEntityManager();
                $query = $em->createQuery(

                        'SELECT partial a.{ediTransactionDetailId, poNumber},
                        partial b.{ediTransactionId, senderId, receiverId, gsNumber, isaNumber, fileName, transactionDate},
                        partial c.{ediDocTypeId, docType}
                        FROM MatrixEdiBundle:EdiTransactionDetail a
                        JOIN a.ediTransaction b
                        JOIN b.ediDocType c
                        WHERE b.fileName LIKE :fileName
                        AND a.poNumber LIKE :poNumber
                        AND c.docType = :doc_type
                        AND a.flag = 1 AND b.flag = 1
                        ORDER BY b.transactionDate desc')

                ->setParameter('poNumber', "%$poNumber%")
                ->setParameter('fileName', "%$fileName%")
                ->setParameter('doc_type', 856)
                ->setFirstResult(($page - 1) * $limit)
                ->setMaxResults($limit);

                $paginator = new Paginator ($query , $fetchJoinCollection = false );
                $paginator->setUseOutputWalkers(false);
                return $paginator;

        }


这用于Edi997Details:

public function getAsnStatus(){

         $em = $this->getEntityManager();
         $query = $em->createQuery(
                 'SELECT  partial a.{id, ak301, ak401},
                 partial b.{errorCode, condition},
                 partial c.{edi997DetailId, errorCodeId, noOfTrans, acceptedTrans},
                 partial d.{ediTransactionId, senderId, receiverId, gsNumber, isaNumber, fileName}
                 FROM MatrixEdiBundle:Edi997SegmentInError a
                 JOIN a.ediAk403ErrorCodes b
                 JOIN a.edi997Details c
                 JOIN c.ediTransaction d
                 WHERE c.errorCodeId != 0
                 AND d.flag = 1');

                 return $query->getResult();


        }


有什么方法可以联接Edi997Details和EdiTransaction表,而DocType和EdiTransactionDetail不会受到影响?我需要一些帮助和想法以解决此问题。我是初学者,也是我第一次访问此网站。

最佳答案

尝试这个 :

 table1 -> table2,table3
 table3 -> table1,table2
 table4 -> table2

select a.column,b.column,c.column,d from table1 a join table2 b join
table3 join table4 d on d.column=b.column where...

关于php - 如何将这些表一起加入,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38113746/

10-10 04:57