次の選択で必要なデータを取得しますが、それを拡張して、すべての明確な欠陥について、正しい長さの製品を含む行が返されるようにします。行が存在しない場合はゼロを返します。
これが選択です
SELECT Product, Defect, sum(Length) AS Length FROM RejectTransaction
WHERE RejectTransaction.TranDate >= '20120620 00:00:00.000'
AND RejectTransaction.TranDate <= '20120620 23:59:59.000'
GROUP BY Product, Defect
ORDER BY Product, Defect;
これが現在の出力です
ProductA寸法560.00
ProductAフィルム40.00
ProductA処理10.00
ProductB寸法220.00
ProductBフィルム640.00
ProductBジェルコート200.00
ProductC寸法60.00
ProductCフィルム1160.00
ProductCマットの欠陥810.00
返品したいもの:
ProductA寸法560.00
ProductAフィルム40.00
ProductA処理10.00
ProductAジェルコート0.00
ProductAマットの欠陥0.00
ProductB寸法220.00
ProductBフィルム640.00
ProductBジェルコート200.00
ProductB処理0.00
ProductBマット欠陥0.00
ProductC寸法60.00
ProductCフィルム1160.00
ProductCマットの欠陥810.00
ProductC処理0.00
ProductCジェルコート0.00
必要に応じて、RejectTransaction(上記のデータのデータ)、Product、およびDefectテーブルを用意します。
申し訳ありませんが、これを非常にきれいにする時間がありません。よろしくお願いします。