-4
私は5つの異なる選択をして、それぞれからデータを取得します。それぞれにWHERE句とAND句があります。これらのデータをすべて取り込んで、1つのクエリに入れてデータを乱すことのない方法はありますか?SQL結合の問題
ビル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
コミット数量コード:
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
私が欲しいのです。私はそれが役立つ可能性がある場合PLEXの内部SQL開発環境で働いています
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'
。
ありがとうございました。詳細情報が必要な場合はお知らせください。
DBMSにタグを付け、サンプルデータを提供し、期待される結果を提供し、これまでの作業を表示してください。 – JohnHC
私はこの答えが不完全でよく頼まれていないことを知っていますが、ダウンウィートに時間を取る人が新しいユーザーに質問する方法を説明するのに時間がかかるのであればいいでしょう(例:http://stackoverflow.com/help/how-to-ask) – RudiDudi
私はいくつかのサンプルデータ形式で、私が正しい情報を私に与えてくれたことを知っています。そして結果として私が望むもの。 –