我有5个不同的选择我运行以从每个中获取数据。每个都有WHERE和AND子句。有没有办法可以将所有这些数据放在一个查询中而不会弄乱数据?
构建SQL:
SELECT
C1.Registration_No AS 'Information Provider GLN',
C1.Note AS 'ManufacturerID (IPC assigned)',
C1.Name AS 'Manufacturer Name',
C1.Old_Building_Code AS 'Physical GLN',
C1.Additional_Note AS 'Location ID (IPC assigned)',
C1.Building_Code AS 'Location ID (Supplier)',
CONCAT(C1.Name,C2.Address1,C2.City,C2.State) AS 'Location Name'
FROM Common_V_Building AS C1
JOIN Common_V_Address As C2
ON C2.PCN = C1.Plexus_Customer_No
AND C2.Address_Key = C1.Address_Key
WHERE C1.Additional_Note IN ('SWL061', 'SPL139')
生产数量代码:
SELECT
P1.Other_Note,
P1.Part_No,
P4.UPC_Code,
P1.Name,
SUM(P5.Quantity) AS 'Production Qty'
FROM Part_V_Part As P1
JOIN Part_V_Part_Attributes AS P4
ON P4.PCN = P1.Plexus_Customer_No
AND P4.Part_Key = P1.Part_Key
JOIN Part_V_Production AS P5
ON P5.Plexus_Customer_No = P1.Plexus_Customer_No
AND P5.Part_Key = P1.Part_Key
WHERE P1.Part_No IN ('07809B', '07810T', '07810K', '07811T', '07811TK', '07812B', '05850T', '05853T')
AND P5.Report_DATE >= '12-21-2016'
AND P5.Report_DATE <= '12-21-2016'
GROUP BY P1.Part_No, P1.Other_Note, P4.UPC_Code, P1.Name, P1.Plexus_Customer_No, P1.Building_Key
库存数量代码:
SELECT
P1.Plexus_Customer_No,
P2.Part_No,
SUM(P1.QUANTITY) AS 'Inventory (after shipments)'
FROM PART_V_CONTAINER AS P1
JOIN PART_V_PART AS P2
ON P2.Plexus_Customer_No = P1.Plexus_Customer_No
AND P2.Part_Key = P1.Part_Key
WHERE ACTIVE = '1'
AND PART_NO IN ('07809B', '07810T', '07810K', '07811T', '07811TK', '07812B', '05850T', '05853T')
GROUP BY P2.Part_No, P1.Plexus_Customer_No
装运数量代码:
SELECT
SP1.PCN,
SP4.Part_No,
SUM(SP3.Quantity) As 'Shipments'
FROM SALES_V_SHIPPER AS SP1
JOIN SALES_V_SHIPPER_LINE AS SP2
ON SP2.PCN = SP1.PCN
AND SP2.SHIPPER_KEY = SP1.SHIPPER_KEY
JOIN SALES_V_SHIPPER_CONTAINER AS SP3
ON SP3.PCN = SP2.PCN
AND SP3.SHIPPER_LINE_KEY = SP2.SHIPPER_LINE_KEY
JOIN PART_V_PART AS SP4
ON SP4.PLEXUS_CUSTOMER_NO = SP2.PCN
AND SP4.PART_KEY = SP2.PART_KEY
WHERE SP4.Part_No IN ('07809B', '07810T', '07810K', '07811T', '07811TK', '07812B', '05850T', '05853T')
AND SP3.Loaded_DATE >= '12-21-2016'
AND SP3.Loaded_DATE <= '12-22-2016'
GROUP BY SP4.Part_NO, SP1.PCN
Commited Qty Code:
SELECT
PO1.PCN,
PO3.PART_NO,
SUM(PO2.QUANTITY) AS 'Committed'
FROM SALES_V_PO_LINE AS PO1
JOIN SALES_V_RELEASE AS PO2
ON PO2.PCN = PO1.PCN
AND PO2.PO_LINE_KEY = PO1.PO_LINE_KEY
JOIN PART_V_PART AS PO3
ON PO3.PLEXUS_CUSTOMER_NO = PO1.PCN
AND PO3.PART_KEY = PO1.PART_KEY
JOIN SALES_V_PO AS PO4
ON PO4.PCN = PO1.PCN
AND PO4.PO_KEY = PO1.PO_KEY
JOIN SALES_V_PO_STATUS AS PO5
ON PO5.PCN = PO4.PCN
AND PO5.PO_STATUS_KEY = PO4.PO_STATUS_KEY
WHERE PO5.PO_STATUS = 'OPEN'
AND PO3.PART_NO IN ('07809B', '07810T', '07810K', '07811T', '07811TK', '07812B', '05850T', '05853T')
GROUP BY PO3.PART_NO, PO1.PCN
我想要的是:
Record_Date,
Registration_No AS 'Information Provider GLN',
Note AS 'ManufacturerID (IPC assigned)',
Name AS 'Manufacturer Name',
Old_Building_Code AS 'Physical GLN',
Additional_Note AS 'Location ID (IPC assigned)',
Building_Code AS 'Location ID (Supplier)',
CONCAT(Name,Address1,City,State) AS 'Location Name',
Other_Note AS 'Product Number (SO#/CO#)',
Part_No AS 'MPN',
UPC_Code AS 'GTIN',
Name AS 'Product Description',
GETDATE() AS 'Inventory Reported For Date',
'8:30 AM' AS 'Submission Time',
SUM(Quantity) AS 'Production Qty',
SUM(QUANTITY) AS 'Shipments',
SUM(Quantity) AS 'Inventory (After Shipments)',
SUM(Quantity) AS 'Committed'
我正在PLEX中的SQL开发环境中工作,如果这可能会有所帮助。
谢谢,如果您需要更多信息,请与我们联系。
答案 0 :(得分:0)
我以前在Plex ERP中工作但不再有权访问。你需要搜索他们的数据库模式,如果我没记错的话,进行搜索(ctrl + m)&#34;%database%table%&#34; (或类似的东西)将返回您需要查看的屏幕。然后,您需要在您提供给我们的表格中查找主要/次要关系。如果您至少可以为每个表格提供高级别信息,我相信有人可以提供更好的答案。