text: select  CONCAT('ACTIVIDAD') as ACTIVIDAD,  
  sum(case when substring(tiempo,9,2)=01 then 1 else 0 end) as '01', 
  sum(case when substring(tiempo,9,2)=02 then 1 else 0 end) as '02', 
  sum(case when substring(tiempo,9,2)=03 then 1 else 0 end) as '03', 
  sum(case when substring(tiempo,9,2)=04 then 1 else 0 end) as '04', 
  sum(case when substring(tiempo,9,2)=05 then 1 else 0 end) as '05', 
  sum(case when substring(tiempo,9,2)=06 then 1 else 0 end) as '06', 
  sum(case when substring(tiempo,9,2)=07 then 1 else 0 end) as '07', 
  sum(case when substring(tiempo,9,2)=08 then 1 else 0 end) as '08', 
  sum(case when substring(tiempo,9,2)=09 then 1 else 0 end) as '09', 
  sum(case when substring(tiempo,9,2)=10 then 1 else 0 end) as '10', 
  sum(case when substring(tiempo,9,2)=11 then 1 else 0 end) as '11', 
  sum(case when substring(tiempo,9,2)=12 then 1 else 0 end) as '12', 
  sum(case when substring(tiempo,9,2)=13 then 1 else 0 end) as '13', 
  sum(case when substring(tiempo,9,2)=14 then 1 else 0 end) as '14', 
  sum(case when substring(tiempo,9,2)=15 then 1 else 0 end) as '15', 
  sum(case when substring(tiempo,9,2)=16 then 1 else 0 end) as '16', 
  sum(case when substring(tiempo,9,2)=17 then 1 else 0 end) as '17', 
  sum(case when substring(tiempo,9,2)=18 then 1 else 0 end) as '18', 
  sum(case when substring(tiempo,9,2)=19 then 1 else 0 end) as '19', 
  sum(case when substring(tiempo,9,2)=20 then 1 else 0 end) as '20', 
  sum(case when substring(tiempo,9,2)=21 then 1 else 0 end) as '21', 
  sum(case when substring(tiempo,9,2)=22 then 1 else 0 end) as '22', 
  sum(case when substring(tiempo,9,2)=23 then 1 else 0 end) as '23', 
  sum(case when substring(tiempo,9,2)=24 then 1 else 0 end) as '24', 
  sum(case when substring(tiempo,9,2)=25 then 1 else 0 end) as '25', 
  sum(case when substring(tiempo,9,2)=26 then 1 else 0 end) as '26', 
  sum(case when substring(tiempo,9,2)=27 then 1 else 0 end) as '27', 
  sum(case when substring(tiempo,9,2)=28 then 1 else 0 end) as '28', 
  sum(case when substring(tiempo,9,2)=29 then 1 else 0 end) as '29', 
  sum(case when substring(tiempo,9,2)=30 then 1 else 0 end) as '30', 
  sum(case when substring(tiempo,9,2)=31 then 1 else 0 end) as '31' 
  from actividad.aralleida_tw 
  where substring(tiempo,6,2)=%actual_month% AND substring(tiempo,1,4)=%actual_year%