SELECT o.*,
       act.fe_ultima_actividad, ifnull(act.dias_ultima_actividad, 9999) as dias_ultima_actividad, ifnull(act.pedidos,0) as pedidos
  FROM vw_oficina o LEFT JOIN
     (
         SELECT a.co_oficina, MAX(date(a.updated_at)) AS fe_ultima_actividad,
                TIMESTAMPDIFF(DAY, MAX(date(a.updated_at)), CURRENT_TIMESTAMP) AS dias_ultima_actividad,
                COUNT(ap.id) AS pedidos
         FROM actividades a LEFT JOIN actividad_pedidos ap
                                      ON a.id = ap.id_actividad
         GROUP BY a.co_oficina
     ) act
   ON o.co_oficina = act.co_oficina
