0

我正在尝试从两个表中制作生产报告,两者都是不同的日期。(下面的表格示例)

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。问题是我需要从两个表中使用两个不同的日期参数,但是当我使用该连接时,它不能正常工作,LEFT OUTER JOIN但是INNER JOIN。(从第一个表我需要所有记录,从第二个只需要 where id=id

表格示例:在此处输入图像描述

结果必须是:

机器ID | 生产时间总和 | 维修时间总和(如果有) - 基于从到到

4

2 回答 2

0

不要加入表格,而是尝试联合它们。类似于以下内容:

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}

然后,您可以轻松地按机器分组并分别汇总所有“生产”行和所有“修复”行。

于 2013-03-14T19:33:23.420 回答
0

您可以在一个“主”报告中嵌入两个子报告。在主报表中定义参数,然后将它们链接到每个子报表。

于 2013-03-14T19:37:15.983 回答