codice:
select coalesce(z,'Tot4') z, `tot1`, `tot2`, (`tot1` + `tot2`) tot3
  from (select
    Z
  , sum(if(A='S', 1, 0)) `tot1`
  , sum(if(P='S', 1, 0)) `tot2`
        from tbl
        group by z with rollup
) x