SELECT t_nr01 as t_nr01,  
       t_p01 as t_p01, 
       if(t_ex<>0, 1, 0) as t_p02, 
       if(t_ex<>0, 1, 0) as t_p03
FROM
(        
      SELECT z28.nr01 as t_nr01, 
             z28.p01  as t_p01, 
             sum(ifnull(z29.nr01, 0)) as t_ex
      FROM z28
      LEFT JOIN z29 ON z29.z28=z28.nr01
                    && z29.z30={nnr01}
      GROUP BY z28.nr01
) as t01
ORDER BY t_nr01;