SELECT tabl01.*, 
       sum( if(i00tot.p610 is not null 
               && i00tot.p610>={peg_xoro1}
               && i00tot.p610<={peg_xoro2},
               ifnull(i00tot.p03, 0), 0)
           ) as pt01, 
       sum( ifnull(i00tot.p03, 0) ) as pt02
FROM 
( {peg_str} ) as tabl01
LEFT JOIN i00tot ON i00tot.pno1=tabl01.v101
GROUP BY tabl01.v101;

