簡単に言えば、これらのテーブルがあります。
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
これらのテーブルには、同じ [日付 | 日付] に対して複数のレコードを含めることができます。マシン | Product]、それらは一意の列ではありません。この出力を得るのに最適な SQL コード (SQLite または SQL Server) は何ですか?
Output:
Date | Machine | Product | Planning | OKParts | ScrapParts | TrialParts | Minutes
編集: 出力では、[Date,Machine,Product] ごとに 1 行が必要で、残りの列は SUM でなければなりません (私は英語を話せません、申し訳ありません)。
Eidted: 例: (表を短くするために「Trials」という表は入れません)
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