select d1.article, d2.locationFrom id_loc, d2.createdat, sum(d1.quantity) over(PARTITION BY d1.article, d2.locationFrom, d2.createdat) sum_quantity from smspec d1, smdocuments d2 where (d1.doctype=d2.doctype) and (d1.doctype='CS') and (d1.docid=d2.id) and (d2.createdat>=TO_DATE('15.10.2012','dd.mm.yyyy')) and (d2.createdat<=TO_DATE('21.10.2012','dd.mm.yyyy')) order by 3,1