SELECT *
FROM

(
select
       a01.nr01 as nr01,
       a01.pnr01 as pnr01,
       i01.p014 as p21,
       sum(i01.p03*i01.p012*i15.p04) as pos,
       a01.p19 as p19
FROM i01
LEFT JOIN i15 ON i15.p01=i01.p05
LEFT JOIN a01 ON a01.p21=i01.p014
LEFT JOIN d00 ON d00.nr01=a01.pnr01

WHERE i01.p01='{npno}'
   && i01.p014 like '30%'
   && {peg_str1}
GROUP BY a01.nr01

) as t1
WHERE pos>0
ORDER BY p19 ;
