select b.id_alu as CODIGO,ape_per as APELLIDO,nom_per as NOMBRE,des_cur as SECCION ,count(nota) as TOTAL from (
select a.* from (
select id_alu,cod_cur,cod_mat
, if((nota-truncate(nota,1))>=0.05 ,round(ceil(nota*10)/10,1),round(nota,1))as nota
from 
(
select id_alu,cod_cur  ,cod_mat, avg(round(nota_d,1)) as nota   from seg_final
group by id_alu,cod_cur,cod_mat
) a0) a 
inner  join rangos_valora r on nota>=min and nota<=max
inner join tipvalora v on v.id_val=r.id_val and v.val_apr='n'
)b 
inner join alumno l using(id_alu)
inner join curso c using (cod_cur)
inner join grado g using (cod_gra)
where est_alu='h' and cod_gra  = VAR01
group by id_alu,cod_cur 
order by cod_cur, TOTAL desc