Select conditioned MySQL WOrkbench

0

How about, I have the following table:

These data I have entered for the moment:

Where you can see that I have the subjects of the students, I need to take out the semester in which each student goes, because in this table he says that he goes in different semesters for the subjects he has, I have taken his semester but I do not I know how to attach it to a query so that I only have the biggest semester and not all the semesters of the student:

With the following query, he managed to take out each student's semester:

SELECT idPro, MAX(Semes) as Semestre FROM Historial
GROUP BY idAlum;

What I need to do is select the number of students in each semester per race. Something like this:

However the query is wrong, because it takes me all the semesters of the student and not the older one, the code is as follows:

    SELECT Programa.idPrograma as carrera, 
(
    SELECT count((SELECT MAX(Semes) FROM Historial WHERE Semes="1er Semestre" GROUP BY idAlum ORDER BY idPro)) FROM Historial
    WHERE Historial.idPro = Programa.idPrograma
    AND Semes = '1er Semestre'
) as 1ro,
(
    SELECT count((SELECT MAX(Semes) FROM Historial WHERE Semes="2do Semestre" GROUP BY idAlum ORDER BY idPro)) FROM Historial
    WHERE Historial.idPro = Programa.idPrograma
    AND Semes = '2do Semestre'
) as 2do,
(
    SELECT count((SELECT MAX(Semes) FROM Historial WHERE Semes="3er Semestre" GROUP BY idAlum ORDER BY idPro)) FROM Historial
    WHERE Historial.idPro = Programa.idPrograma
    AND Semes = '3er Semestre'
) as 3ro  FROM Programa;

Beforehand, Thank you.

    
asked by Gael Rodriguez 30.05.2018 в 22:57
source

0 answers