EDIT
I made the query work with the help of Hockenberry! Thanks. But i have one more problem. My timeplan table structure is in fact as follows.
Material no|Production time|Production place
12345|2,10|Robot
12345|7,40|Machining
67890|2,34|Machining
34567|9,93|Manuel
My query just takes the time from timeplan table if it matches the production place from table report.
i want query result to add second production place's production time to the sum grouping by [Production date],[Production place],[Shift]
in other words i dont want to group the query by Report.ID, Report.[Creation date], Report.[Responsible] and Report.[Number of Workers], but Timeplan.[Production place]. But i want this results on the row thats being taken from report table.
SELECT *,
(TotalInterruptDuration + TotalReworkDuration + TotalOvertimeDuration) AS TotalSum
FROM (
SELECT
Report.ID,
Report.[Creation date],
Report.[Production date],
Report.[Production place],
Report.[Shift],
Report.[Responsible],
Report.[Number of workers],
(SELECT Sum(Interrupts.[Interrupt duration])
FROM Interrupts
WHERE Interrupts.ID=Report.ID) AS TotalInterruptDuration,
(SELECT Sum([Rework].[Rework duration])
FROM [Rework]
WHERE [Rework].ID=Report.ID) AS TotalReworkDuration,
(SELECT Sum(Overtime.[Overtime duration])
FROM Rework
WHERE Rework.ID=Report.ID) AS TotalOvertimeDuration,
Year([Report]![Production date]) AS Year,
DatePart("ww",[Report]![Production date]-1) AS Week,
Month(Report![Production date]) AS Month,
Sum(Quantity.[Quantity] * Timeplan.[Production.time]) AS CalcValue
FROM (Report
INNER JOIN Quantity ON Quantity.ID = Report.ID)
INNER JOIN Timetable ON Report.[Production place] = Timetable.[Production place] AND Quantity.[Material no] = Timeplan.[Material no]
GROUP BY Report.ID, Report.[Creation date], Report.[Production date], Report.[Production place], Report.[Shift], Report.[Responsible], Report. [Number of workers])
tmp
..............................................
First of all sorry for my bad English. I have a query as follows.
SELECT
Report.ID,
Report.[Creation date],
Report.[Production date],
Report.[Production place],
Report.[Shift],
Report.[Responsible],
Report.[Number of workers],
(SELECT Sum(Interrupts.[Interrupt duration])
FROM Interrupts
WHERE Interrupts.ID=Report.ID) AS TotalInterruptDuration,
(SELECT Sum([Rework].[ Rework duration])
FROM [Rework]
WHERE [Rework].ID=Report.ID) AS TotalReworkDuration,
(SELECT Sum(Overtime.[Overtime duration])
FROM Overtime
WHERE Overtime.ID=Report.ID) AS TotalOvertimeDuration,
Year([Report]![Production date]) AS Year,
DatePart("ww",[Report]![Production date]-1) AS Week,
Month(Report![Production date]) AS Month
FROM Report
My first question is I would like to Sum TotalInterruptDuration, TotalReworkDuration, TotalOvertimeDuration in the same row.
And second question which far more important is; I want to join Report and Quantity table if ID matches and multiply Report.[Number of Workers] with sum of [Production time] derived from corresponding [Material no] by joining [Quantity] and [Timeplan] tables.
For example i want to look table quantity for id(1) and then multiply production time of material 12345 with 10(quantity) and production time of 67890 and multiply it with 11(quantity) and production time of 34567 and multiply it with 7 (quantity) and sum values and print in the query.
My tables look like this.
**Table Report**
*ID Creation date Production date Production place Shift Responsible Number of workers*
1 01.01.2015 01.01.2015 Robot 2 Omer 12
2 02.01.2015 02.01.2015 Robot 3 Erdem 15
3 03.01.2015 03.01.2015 Machining 2 Sukru 4
4
**Table Quantity**
*ID Quantity Material No*
1 10 12345
1 11 67890
1 7 34567
2 3 12345
3 6 67890
3 6 34567
4 5 12345
**Table Timeplan**
*Material No Production Time*
12345 34
67890 11
34567 21