sql多表联合统计

2025-01-03 07:29:39
推荐回答(2个)
回答1:

SELECT ItemCode, OpenQty
FROM Rdr1
WHERE (LineStatus <> 'R')

SELECT ItemCode, SUM(PlannedQty - IssuedQty)
FROM Wor1
WHERE (DoCentry NOT IN (
SELECT DoCentry
FROM Owor
WHERE ([Status] = 'R')
))
GROUP BY ItemCode

SELECT ItemCode, SUM(PlannedQty - CmpltQty)
FROM Owor
WHERE ([Status] = 'R')
GROUP BY ItemCode

SELECT ItemCode, SUM(OpenQty)
FROM Por1
WHERE (LineStatus <> 'c')
GROUP BY ItemCode

SELECT ItemCode, SUM(IsCommited),SUM(OnOrder)
FROM Oitw
GROUP BY ItemCode

--查询 rdr1表和wor1之和;Owor表和por1之和得出结果,和oitw表比较不同的查出来。
--问题补充:

SELECT ItemCode
FROM Oitw
WHERE (SUM(IsCommited) - OpenQty - SUM(PlannedQty - IssuedQty))
AND (SUM(OnOrder) - SUM(PlannedQty - CmpltQty) - SUM(OpenQty))
ORDER BY ItemCode

----------------------------------------------

WHERE (SUM(IsCommited) - OpenQty - SUM(PlannedQty - IssuedQty))
AND (SUM(OnOrder) - SUM(PlannedQty - CmpltQty) - SUM(OpenQty))

这两个条件我看不懂,因为不是逻辑表达式。

回答2:

select itemcode,openqty from rdr1 where linestatus<>'R'
select itemcode,sum(plannedqty-issuedqty) from wor1 where docentry not in (select docentry from owor where status='R')
group by itemcode
select itemcode,sum(plannedqty-cmpltqty) from owor where status='R' group by itemcode
select itemcode,sum(openqty) from por1 where linestatus<>'c' group by itemcode
select itemcode,sum(iscommited),sum(onorder) from oitw group by itemcode