select sum(rat), dat from ( select distinct (s.dateexec) dat, 1 rat, summ from ( select sum(coddoc) summ, one.dateexec dat from stkdocs one where one.coddoc < 120000 group by one.dateexec order by one.dateexec) two, stkdocs s where two.dat <= s.dateexec and s.coddoc < 120000) thr group by thr.dat order by thr.dat ------------------ 1 17.10.2001 2 24.10.2001 3 29.10.2001 4 30.10.2001 5 31.10.2001 6 01.11.2001 7 02.11.2001 8 05.11.2001 9 06.11.2001 10 08.11.2001 11 10.11.2001 12 15.11.2001 13 20.11.2001