Select l.m_names, Sl1.LPU_ID,SUM(OKS) OKS,SUM(OKS_LET) OKS_LET,
       SUM(ONMK_1) ONMK_1,
       SUM(ONMK_2) ONMK_2,
       SUM(ONMK_3) ONMK_3,
       SUM(ONMK_LET) ONMK_Let From
    (Select
    Case when (Sl.Lpu_Id is not null and (SUBSTR(SL.DS1,1,3)='I21' or SL.DS1='I20.0' or SUBSTR(SL.DS1,1,3)='I22' or SUBSTR(SL.DS1,1,3)='I23' or SUBSTR(SL.DS1,1,3)='I24')) or
           (Sl.Lpu_Id is not null and (SUBSTR(SL.DS1,1,3) in ('I60','I61','I62','I63','I64') or SUBSTR(SL.DS1,1,3) in ('G45','G46')))
           Then SL.LPU_ID Else Null end  LPU_ID,
    Case when SUBSTR(SL.DS1,1,3)='I21' or SL.DS1='I20.0' or SUBSTR(SL.DS1,1,3)='I22' or SUBSTR(SL.DS1,1,3)='I23' or SUBSTR(SL.DS1,1,3)='I24' Then 1 Else Null end OKS,
    Case when (SUBSTR(SL.DS1,1,3)='I21' or SL.DS1='I20.0' or SUBSTR(SL.DS1,1,3)='I22' or SUBSTR(SL.DS1,1,3)='I23' or SUBSTR(SL.DS1,1,3)='I24')  and rslt in (105,106) Then 1 Else Null end OKS_LET,
    Case when SUBSTR(SL.DS1,1,3) = 'I63'  Then 1 Else Null end ONMK_1,
    Case when SUBSTR(SL.DS1,1,3) in ('I60','I61','I62')  Then 1 Else Null end ONMK_2,
    Case when SUBSTR(SL.DS1,1,3) in ('G45','G46') Then 1 Else Null end ONMK_3,
    Case when (SUBSTR(SL.DS1,1,3) in ('I60','I61','I62','I63','I64') or SUBSTR(SL.DS1,1,3) in ('G45','G46')) and rslt in (105,106) Then 1 Else Null end ONMK_let
    From MTR.S19_SCHET S,MTR.S19_ZAP Z, MTR.S19_SL SL
    Where S.YEAR=$SY$ and Z.Code=S.Code and Z.USL_OK=1 and Z.SUMP>0 and SL.ID_ZAP=Z.ID_ZAP and
          ((SUBSTR(SL.DS1,1,3)='I21' or SL.DS1='I20.0' or SUBSTR(SL.DS1,1,3)='I22' or SUBSTR(SL.DS1,1,3)='I23' or SUBSTR(SL.DS1,1,3)='I24')
          or (SUBSTR(SL.DS1,1,3) in ('I60','I61','I62','I63','I64') or SUBSTR(SL.DS1,1,3) in ('G45','G46')))
    ) SL1, MTR.LPU L
    Where Sl1.Lpu_Id=L.LPU_ID
    group by l.m_names, Sl1.LPU_ID