I have three tables in SQL Server, 2 tables save many items of product such as product number, product name and product line and another table save stop time of machine.
I have written this code but I cant join 2 queries into one:)
(select
Query4.prdline, Query4.prdproduction, Query4.SumOfProduced,
(Query3.SumOfTime)
from
(select
Table_production.prdline, Table_production.prdproduction,
sum(Table_stop.stoptime) AS SumOfTime
from
Table_production
inner join
Table_stop ON Table_production.prdID = Table_stop.formnum
where
(((Table_production.[prddate]) Between '1397/08/01' And '1397/08/30'))
group by
Table_production.prdline, Table_production.prdproduction) Query3,
(select
(t.prdline), (t.prdproduction), sum(t.prdnum) AS SumOfProduced
from
(select
prdnum, prdtime, prdproduction, prdline
from
Table_production
where
(prddate between '1397/08/01' and '1397/08/30')
union all
select
nprdnum, nprdtime, nprdproduction, nprdline
from
Table_Nextproduction
where
(nprddate between '1397/08/01' and '1397/08/30')
) T
group by
T.prdline, T.prdproduction) Query4)