Select /*+ORDERED*/Z.LPU,COUNT(*),TO_CHAR(SUM(SL.SUM_M)) 
From mtr.s19_zap Z, MTR.INOSTR C,mtr.s19_SL SL,Mtr.V002 V Where 
V.ID_PROFIL=SL.PROFIL and SL.DATE_2 Between V.DATE_B and V.DATE_E
and SL.ID_ZAP=Z.ID_ZAP
and ((Z.SPOLIS=C.SPOLIS and Z.NPOLIS=C.NPOLIS) or Z.NPOLIS=C.NPOLIS)
And z.Code in (Select code from mtr.s19_Schet where dschet between TO_DATE('$SD$.$SM$.$SY$','DD.MM.YYYY') and TO_DATE('$ED$.$EM$.$EY$','DD.MM.YYYY'))
and SUMP>0
Group by Z.LPU
