0

日付が異なる2つのテーブルから本番レポートを作成しようとしています。(以下の表の例)

first table (machine ID, production time, date)
-result should be sum of time group by machine ID (parameters - date from - to)

second table (machine ID, repair time, date)
-result should be sum of repair time group by(parameters - date from-to).

レポートでは、両方のテーブルの合計でカウントする必要があります(例:) from 1.1.2013 to 10.1.2013。問題は、両方のテーブルから2つの異なる日付パラメータを使用する必要があることですが、その接続を使用すると、次のように機能しませんLEFT OUTER JOININNER JOIN(firtsテーブルからはすべてのレコードが必要で、2番目からはここでのみid=id

表の例:ここに画像の説明を入力してください

結果は次のようになります。

machineID | 生産時間の合計| 修理時間の合計(ある場合)-from-toに基づく

4

2 に答える 2

0

Instead of joining the tables, try unioning them instead. Something like the following:

SELECT machineID, spent_time as time, production_date as date, 'Production' as type
FROM table1
WHERE production_date between {?date_from} and {?date_to}

UNION

SELECT machineID, repair_time as time, repair_date as date, 'Repair' as type
FROM table2
WHERE repair_date between {?date_from} and {?date_to}

Then you can easily group by machine and sum all 'Production' rows and all 'Repair' rows separately.

于 2013-03-14T19:33:23.420 に答える
0

1 つの「メイン」レポートに 2 つのサブレポートを埋め込むことができます。メイン レポートでパラメータを定義してから、それらを各サブレポートにリンクします。

于 2013-03-14T19:37:15.983 に答える