update alum_grado ag, (
	select id_alu , apr.tot_are_per,max_mat_perd,if( (tot_are_per is null and por is null ),'Aprobado',if(apr.tot_are_per>=max_mat_perd or por is not null , 'No Aprobado','Aprobado')) as aprueba
	from alumno ax
	left join(
		select id_alu,count(are_fin) as tot_are_per from (
			select id_alu,are_fin, nota_d as def from (
				select * from seg_final inner join area using(cod_are) where cod_mat=0 and id_peri in(select id_peri from periodo where per_fin='n' and per_not_fin='s') and 
(nor_are='n' or 's'=(select val_var from _sapred where nom_var='APROBAR_ANIO_CON_NORMALIZACION'))
			) t
			inner join rangos_valora r on round(t.nota_d,1) >= r.min and round(t.nota_d,1) <= r.max
			inner join tipvalora v on v.id_val=r.id_val
			where val_apr='n'
		) xx
		group by id_alu
	) apr using(id_alu)
	inner join anolectivo on actual='s'
	left join (
		select id_alu,cod_mat,cod_cur, total,inh_mat*sem_mat as total_h,(total*100/(inh_mat*sem_mat)) as por
		from (
			select id_alu,cod_mat,cod_cur, sum(num_hor) total from falta_histo_mat
			where  jus_fal='injust'
			group by id_alu,cod_mat,cod_cur
			order by id_alu, cod_mat,cod_cur
		) s
		inner join matgra using(cod_cur,cod_mat)
		inner join _sapred on(nom_var='PORCENTAJE_FALTAS_PERDER_MATERIA')
		where  (total*100/(inh_mat*sem_mat)) > val_var
		
		
	) sx using(id_alu)
	where est_alu='h'
	order by id_alu
) apr set ag.apro_alu=if(ag.asig='s',apr.aprueba,'Cursando') where ag.id_alu=apr.id_alu AND ag.obs_apro is null /*CAD_WHERE*/