所以我有一个我正在研究的问题,我不能让它做我想做的事。我需要它来返回组成产品的所有部分,如果它在完成的顺序中有一个与它关联的partLotNumber,我想在另一列(IE左边的连接)中得到它。我可以得到我的查询以获得构成产品的所有部件,并且我可以在完成的产品中获得所有的partlotnumbers但我无法让它同时完成。到目前为止,我的所有尝试都输出每个partLotNumber的每个部分。
此查询返回构成产品的所有部分
SELECT orders.orderNumber, orderline.orderlineID, products.productID, assembly.assemblyID, assemblyparts.partID, parts.name
FROM orders
LEFT JOIN orderline ON orders.orderNumber = orderline.orderNumber
LEFT JOIN products ON orderline.productID = products.productID
LEFT JOIN assemblyproduct ON products.productID = assemblyproduct.productID
LEFT JOIN assembly ON assemblyproduct.assemblyID = assembly.assemblyID
INNER JOIN assemblyparts ON assemblyproduct.assemblyID = assemblyparts.assemblyID
LEFT JOIN parts ON assemblyparts.partID = parts.partID
WHERE orders.orderNumber = 1024
并且此查询返回成品的所有部分。
SELECT orders.orderNumber, orderline.orderlineID, products.productNumber, assemblyproduct.assemblyID, lotrecord.finishedLotNumber, assemblylot.assemblyLotNumber, assemblyline.assemblylineID, assemblyline.partLotNumber, parts.name
FROM orders
LEFT JOIN orderline ON orders.orderNumber = orderline.orderNumber
LEFT JOIN products ON orderline.productID = products.productID
LEFT JOIN assemblyproduct ON products.productID = assemblyproduct.productID
LEFT JOIN assembly ON assemblyproduct.assemblyID = assembly.assemblyID
LEFT JOIN lotrecord ON products.productID = lotrecord.productID
LEFT JOIN finishedlotinventory ON lotrecord.finishedLotNumber = finishedlotinventory.finishedLotNumber
LEFT JOIN assemblylot ON finishedlotinventory.assemblyLotNumber = assemblylot.assemblyLotNumber
LEFT JOIN assemblyline ON assemblylot.assemblyLotNumber = assemblyline.assemblyLotNumber
LEFT JOIN inventory ON assemblyline.partLotNumber = inventory.partLotNumber
LEFT JOIN parts ON inventory.partID = parts.partID
WHERE orders.orderNumber = '1038'
基本上我想要做的是选择一个订单号,它返回所有的订单行,该订单行中的产品,然后是组成该产品的组件,然后是组成组件的部件,如果它已被提交到装配线表,我想返回与该订单关联的partLotNumber。到目前为止,我只能完成订单显示,我不能得到不完整的订单。
这是我的db图的图片,为了清晰起见,省略了一些表格。