select n_akt, TO_CHAR(date_akt, 'DD.MM.YYYY')as date_akt, smo, n_exp, err_sl, not_opl_sl, not_opl_sum, shtraf_sl, shtraf_sum, 
type, type_exp, expert, lpu, nschet, TO_CHAR(dschet, 'DD.MM.YYYY')as dschet, n_zap, idcase, sl_id, vpolis, spolis, npolis, 
sumv, s_sum,s_tip,s_osn,s_ist, fam, im, ot, TO_CHAR(dr, 'DD.MM.YYYY') as dr, usl_ok, TO_CHAR(date_1, 'DD.MM.YYYY') as date_1, TO_CHAR(date_2, 'DD.MM.YYYY') as date_2, ds1, sump
From 
(select /*+ORDERED*/ distinct Z.ID,n_akt, date_akt, t.smo, n_exp, err_sl, not_opl_sl, not_opl_sum, shtraf_sl, shtraf_sum, 
type, type_exp, expert, z.lpu, nschet, dschet, z.n_zap, z.idcase, z.sl_id, z.vpolis, z.npolis, z.spolis, 
z.sumv, fam, im, ot, dr, usl_ok, date_1, date_2, ds1, sump
from MTR.EXP_AKT t,mtr.exp_zap z, mtr.s19_zap z1, mtr.s19_sl sl   
where t.date_I <= TO_DATE('$ED$.$EM$.$EY$','DD.MM.YYYY') and t.date_I >= TO_DATE('$SD$.$SM$.$SY$','DD.MM.YYYY')and z.akt = t.id and z1.code = z.code and z1.n_zap =z.n_zap 
and sl.id_zap = z1.id_zap) D,
(select  /*+ORDERED*/ Sa.Zap,s_sum,s_tip,s_osn,s_ist from mtr.exp_sank sa, mtr.exp_osn o where  o.id = sa.id) E
Where E.ZAP(+)=D.ID order by TO_DATE(date_akt,'DD.MM.YYYY') desc
