Unknown column 'm.alias' in 'field list' SQL=SELECT m.id, m.alias, UPPER(LTRIM(m.name)) AS name, ( COALESCE(medo1.total,0) + COALESCE(medo2.total,0) ) AS med_o, ( COALESCE(medp1.total,0) + COALESCE(medp2.total,0) ) AS med_p, ( COALESCE(medb1.total,0) + COALESCE(medb2.total,0) ) AS med_b, ( SELECT COUNT( dc.id_disciplina ) FROM nkp7c_aa_participantes_cats dc RIGHT JOIN nkp7c_aa_participantes dp ON dp.id = dc.id_participante WHERE dp.id_institucion = m.id ) AS disciplinas FROM nkp7c_aa_instituciones m LEFT JOIN( SELECT mi.id_institucion, SUM(mm.value) AS total FROM nkp7c_aa_medallas_ins mi RIGHT JOIN nkp7c_aa_medallas mm ON mm.id = mi.id_medalla WHERE mm.type = 1 AND mm.state = 1 AND mm.value >= 1 GROUP BY mi.id_institucion ) medo1 ON medo1.id_institucion = m.id LEFT JOIN( SELECT mp.id_institucion, SUM(mm.value) AS total FROM nkp7c_aa_medallas_par mi RIGHT JOIN nkp7c_aa_participantes mp ON mp.id = mi.id_participante RIGHT JOIN nkp7c_aa_medallas mm ON mm.id = mi.id_medalla WHERE mm.type = 1 AND mm.state = 1 AND mm.value < 1 GROUP BY mp.id_institucion ) medo2 ON medo2.id_institucion = m.id LEFT JOIN( SELECT mi.id_institucion, SUM(mm.value) AS total FROM nkp7c_aa_medallas_ins mi RIGHT JOIN nkp7c_aa_medallas mm ON mm.id = mi.id_medalla WHERE mm.type = 2 AND mm.state = 1 AND mm.value >= 1 GROUP BY mi.id_institucion ) medp1 ON medp1.id_institucion = m.id LEFT JOIN( SELECT mp.id_institucion, SUM(mm.value) AS total FROM nkp7c_aa_medallas_par mi RIGHT JOIN nkp7c_aa_participantes mp ON mp.id = mi.id_participante RIGHT JOIN nkp7c_aa_medallas mm ON mm.id = mi.id_medalla WHERE mm.type = 2 AND mm.state = 1 AND mm.value < 1 GROUP BY mp.id_institucion ) medp2 ON medp2.id_institucion = m.id LEFT JOIN( SELECT mi.id_institucion, SUM(mm.value) AS total FROM nkp7c_aa_medallas_ins mi RIGHT JOIN nkp7c_aa_medallas mm ON mm.id = mi.id_medalla WHERE mm.type = 3 AND mm.state = 1 AND mm.value >= 1 GROUP BY mi.id_institucion ) medb1 ON medb1.id_institucion = m.id LEFT JOIN( SELECT mp.id_institucion, SUM(mm.value) AS total FROM nkp7c_aa_medallas_par mi RIGHT JOIN nkp7c_aa_participantes mp ON mp.id = mi.id_participante RIGHT JOIN nkp7c_aa_medallas mm ON mm.id = mi.id_medalla WHERE mm.type = 3 AND mm.state = 1 AND mm.value < 1 GROUP BY mp.id_institucion ) medb2 ON medb2.id_institucion = m.id WHERE m.application_id = 10 AND m.state = 1 AND m.type = 'instituciones' HAVING disciplinas > 0 ORDER BY med_o DESC, med_p DESC, med_b DESC, m.name LIMIT 10

Próximamente