还有一种简单简单的办法,就是把pr_line和pr_header表连在一起,用括号括起来,作为一个子查询,去和po_line_locations_all做外关联
--以上是网友ideal 的提议.
Ideal 说:
你连接得不对。不知要连pr_line表,其他的地方也要加上外联结
--他说的原因.我想也是这样,一定是哪里有外连接,而我并不清楚.
所以还是采用他的建议;就是把pr_line和pr_header表连在一起,用括号括起来,作为一个子查询,去和po_line_locations_all做外关联
关于外连接以前只是字面上的理解,现在遇到了,才知道数据库的基础知识重要.再次感慨一下.[@more@]
以前一直想解决的就是输PO号,能购查询出来转化而来的PR号,最开始的研究结果是:
采购单找到请购单
通过采购单找到请购单的过程非常麻烦:
/* Formatted on 2006/03/30 14:35 (Formatter Plus v4.8.6) */
SELECTpod.req_header_reference_num,prh.segment1
FROM
po_headers_all poh,
po_distributions_all pod,
po_req_distributions_all prod,
po_line_locations_all poll,
po_requisition_lines_all prl,
po_requisition_headers_all prh
WHEREprh.requisition_header_id=prl.requisition_header_id
ANDprod.requisition_line_id=prl.requisition_line_id
ANDprod.distribution_id = pod.req_distribution_id
ANDpoll.line_location_id=pod.line_location_id
ANDpoll.po_header_id=poh.po_header_id
ANDpoh.segment1='20500214'
涉及几个表相关联,具体是:
po_headers_all poh,--采购单头
po_distributions_all pod,--采购单分部
po_req_distributions_all prod,--请购单分部
po_line_locations_all poll,--
--这个表做什么的,还不清楚,但是如果连接采购单和请购单,必须通过此table
po_requisition_lines_all prl,--请购单行
po_requisition_headers_all prh--请购单行
再后来网友提示不需要采购单,请购单分布属性,那么就可以这样:
SELECTprh.segment1,pol.from_line_id,pol.*
FROMpo_lines_all pol,
po_headers_all poh,
po_line_locations_all poll,
po_requisition_headers_all prh,