WHERE a.mattype (+) = c.mattype AND b.mattype (+) = c.mattype AND
a.matname (+) = c.matname AND c.matname = b.matname (+) AND
c.spec = a.spec (+) AND c.spec = b.spec (+) AND
c.backdate = b.outdate (+) AND c.backdate = a.indate (+)
GROUP BY c.mattype, c.matname, c.spec, c.backdate) a,
(SELECT a.mattype, a.matname, a.spec, a.indate, SUM(nvl(a.amount, 0)
- NVL(b.amount, 0) + NVL(c.amount, 0)) AS amount, SUM(nvl(a.matsum,
0) - NVL(b.matsum, 0) + NVL(c.matsum, 0)) AS matsum
FROM (SELECT a.mattype AS mattype, a.matname AS matname,
a.spec AS spec, b.indate AS indate, a.amount AS amount,
a.matsum AS matsum, b.matsource AS matsource
FROM materialin a, matin b
WHERE b.serial = a.serial) a, matuse b, matback c
WHERE a.mattype = b.mattype (+) AND a.mattype = c.mattype (+) AND
a.matname = b.matname (+) AND a.matname = c.matname (+) AND
a.spec = b.spec (+) AND a.spec = c.spec (+) AND
a.indate = b.outdate (+) AND a.indate = c.backdate (+)
GROUP BY a.mattype, a.matname, a.spec, a.indate
UNION
SELECT b.mattype, b.matname, b.spec, b.outdate AS indate,
SUM(nvl(a.amount, 0) - NVL(b.amount, 0) + NVL(c.amount, 0))
AS amount, SUM(nvl(a.matsum, 0) - NVL(b.matsum, 0)
+ NVL(c.matsum, 0)) AS matsum
FROM (SELECT a.mattype AS mattype, a.matname AS matname,
a.spec AS spec, b.indate AS indate, a.amount AS amount,
a.matsum AS matsum, b.matsource AS matsource
FROM materialin a, matin b
WHERE b.serial = a.serial) a, matuse b, matback c
WHERE a.mattype (+) = b.mattype AND b.mattype = c.mattype (+) AND
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/ruanjian/article-30385-29.html
烊烊加油
具有领海和专属经济区