SELECT (D.SaleID) as Field12,
trunc((D.SaleDate)) as Field13,
(D.Article) as Field1,
(CRD.Name) as Field10,
trunc((D.IncomeDate)) as Field3,
(D.IncomeID) as Field9,round((SUM(D.Quantity)),3) as Field6,
round((decode(round((SUM(D.Quantity)),3),0,0,round((SUM((decode(D.IncomeQ,0,0,round(D.IncomeSum*D.Quantity/D.IncomeQ,4))))),4)/round((SUM(D.Quantity)),3))),2) as Field11,
round((SUM((decode(D.IncomeQ,0,0,round(D.IncomeSum*D.Quantity/D.IncomeQ,4))))),4) as Field8,
round((SUM((decode(D.SaleQ,0,0,round(D.SaleSum*D.Quantity/D.SaleQ,4))))),4) as Field7
FROM SVCardName CRD,FVMapRepOpen D
WHERE D.Article=CRD.Article and ((D.SaleOp=1 and D.SaleUserOp is null))
and D.article='023965'
and D.SaleDate between to_date('01.09.2017','DD.MM.YYYY') and to_date('02.10.2017','DD.MM.YYYY')
GROUP BY (D.Article),trunc((D.IncomeDate)),(D.IncomeID),(CRD.Name),(D.SaleID),trunc((D.SaleDate))
ORDER BY 4 ASC,5 ASC;