WITH CARI_EKSTRECTE AS 
(
select ROW_NUMBER () OVER (PARTITION by M.MUSNO order by A.TARIH,A.CARINO) SIRA,
M.MUSNO,A.TARIH, A.CARINO,M.MUSADI,(BORC-ALACAK) TUTAR,-- COUNT(*) sayi,
SUM(BORC-ALACAK) OVER (PARTITION by M.MUSNO order by A.TARIH,A.CARINO) BAKIYE 
from ACARI A , AMUSTERI M WHERE A.MUSNO=M.MUSNO -- AND A.MUSNO=126

)
SELECT * FROM CARI_EKSTRECTE ORDER BY MUSNO,SIRA

