SELECT SUM(QUANT) FROM (SELECT MAX(FFMapRep.INCOMEQ) - MAX(FFMapRep.SALEQ) QUANT FROM FFMapRep WHERE FFMapRep.article = '0003672' AND SALEDATE <= to_date('01.03.2007', 'DD.MM.YYYY') AND nvl(SALELOCATIONFROM, SALELOCATIONTO) IN(6))
SELECT SUM(QUANT), (SELECT MAX(FFMapRep.INCOMEQ) - MAX(FFMapRep.SALEQ) QUANT FROM FFMapRep WHERE FFMapRep.article = '0003672' AND SALEDATE <= to_date('01.03.2007', 'DD.MM.YYYY') AND nvl(SALELOCATIONFROM, SALELOCATIONTO) IN(6)) FROM FFMAPREP
SELECT SUM(INCOMEQUANT) FROM(
SELECT
INCOMEID,
MAX(INCOMEQ) INCOMEQUANT
FROM ffmaprep
WHERE
ARTICLE='0003672'
AND SALEDATE <= to_date('01.03.2007', 'DD.MM.YYYY')
AND nvl(SALELOCATIONFROM, SALELOCATIONTO) IN(6)
GROUP BY INCOMEID
)
SELECT SUM(SALEQUANT) FROM(
SELECT
SALEID,
MAX(SALEQ) SALEQUANT
FROM ffmaprep
WHERE
ARTICLE='0003672'
AND SALEDATE <= to_date('01.03.2007', 'DD.MM.YYYY')
AND nvl(SALELOCATIONFROM, SALELOCATIONTO) IN(6)
GROUP BY SALEID
)
select (первый запрос)-(второй запрос) from dual
select sum(quant),(первый запрос)-(второй запрос) from откуда берешь quant
SELECT StoreLoc, Article, IncomeId, IncomeType, IncomeSpecItem, max(GoodsOwner) GoodsOwner, max(IncomeClientIndex) ClientIndex, max(IncomeVatRate) VatRate, max(IncomeQ) DocQuantity, max(IncomeSum) DocSum, max(IncomeNoVat) DocSumNoVat, ForcedMapping, sum(Quantity) Quantity FROM ( SELECT /*+ ORDERED USE_NL(S,A) FULL(A) FULL(M.U_MapRep.FFMapRep) */ SaleLocationTo StoreLoc, Article, IncomeId, IncomeType, IncomeSpecItem, GoodsOwner, IncomeClientIndex, IncomeVatRate, IncomeQ, IncomeSum, IncomeNoVat, ForcedMapping, Quantity FROM FVMapRep WHERE SaleDate between :date_start and :date_end and forcedMapping=0 and SaleLocationTo is not NULL UNION ALL SELECT /*+ ORDERED USE_NL(S,A) FULL(A) FULL(M.U_MapRep.FFMapRep) */ SaleLocationFrom StoreLoc, Article, IncomeId, IncomeType, IncomeSpecItem, GoodsOwner, IncomeClientIndex, IncomeVatRate, IncomeQ, IncomeSum, IncomeNoVat, ForcedMapping, -Quantity FROM FVMapRep WHERE SaleDate between :date_start and :date_end and forcedMapping=0 and SaleLocationFrom is not NULL ) GROUP BY StoreLoc, Article, IncomeId, IncomeType, IncomeSpecItem, ForcedMapping HAVING ROUND(sum(Quantity),3) <> 0
SELECT SUM(QUANT), (SELECT MAX(FFMapRep.INCOMEQ) - MAX(FFMapRep.SALEQ) QUANT FROM FFMapRep WHERE FFMapRep.article = '0003672' AND SALEDATE <= to_date('01.03.2007', 'DD.MM.YYYY') AND nvl(SALELOCATIONFROM, SALELOCATIONTO) IN(6)) FROM FFMAPREP