简单地说,我有这些表。
Planning:
Date | Machine | Product | PlanningParts
OKParts:
Date | Machine | Product | OKParts
Scrap:
Date | Machine | Product | ScrapParts
Trials:
Date | Machine | Product | TrialParts
Breakdowns:
Date | Machine | Product | Minutes
这些表可以有两个或多个相同的 [Date | 机器 | Product],它们不是唯一的列。获得此输出的最佳 SQL 代码(SQLite 或 SQL Server)是什么?
Output:
Date | Machine | Product | Planning | OKParts | ScrapParts | TrialParts | Minutes
编辑:在输出中,每个 [Date,Machine,Product] 我需要一行,其余列必须是 SUM(我不会说英语,抱歉)
Eidted:示例:(我不会将表格“试用”以使其更短)
Planning:
Date | Machine | Product | PlanningParts
1/6/12 | Blower | A001 | 100
2/6/12 | Blower | A002 | 100
2/6/12 | Assembly| B001 | 50
OKParts:
Date | Machine | Product | OKParts
1/6/12 | Blower | A001 | 50
1/6/12 | Blower | A001 | 20
1/6/12 | Blower | A002 | 100
Scrap:
Date | Machine | Product | ScrapParts | Reason
1/6/12 | Blower | A001 | 5 | Low Weight
1/6/12 | Blower | A001 | 3 | High Weight
2/6/12 | Assembly| B001 | 4 | Bad Cut
Breakdowns
Date | Machine | Product | Minutes | Reason
1/6/12 | Blower | A001 | 100 | Manteinance
1/6/12 | Blower | A001 | 20 | Manteinance
2/6/12 | Assembly| B001 | 100 | Quality approval
OUTPUT:
Date | Machine | Product | Planning | OKParts | ScrapParts | Breakdowns
1/6/12 | Blower | A001 | 100 | 70 | 8 | 120
1/6/12 | Blower | A002 | 100 | 100 | 0 | 0
2/6/12 | Assembly| B001 | 50 | 0 | 4 | 100