|SELECT /*+ INDEX (D SMDOCUMENTS_CREATEDAT) */ | d.ID, d.createdat datedoc, d.locationfrom mxid, t.taxrate ndsinfo, SUM (s.quantity) quantity, SUM (s.totalprice) sumprice, SUM (s.totalpricenotax) sumpricenonds | FROM supermag.smdocuments d, supermag.smspec s, supermag.smspectax t | WHERE d.doctype = 'CS' | AND d.docstate = 3 | AND d.createdat BETWEEN '" + Лев(НачПериода, 10) + "' AND '" + Лев(КонПериода, 10) + "' | AND s.doctype = d.doctype | AND s.docid = d.ID | AND t.doctype(+) = s.doctype | AND t.docid(+) = s.docid | AND t.specitem(+) = s.specitem |GROUP BY d.createdat, d.ID, d.clientindex, d.locationfrom, t.taxrate |ORDER BY d.createdat