Select between several tables MYSQL WORKBENCH

0

How about,

My question is, I have several tables, which I show below where I highlight the relevant data for the query.

I want to ask a question, where do I get the number of students per semester of each Program. Something like this:

I have a consulate that gives me in which semester each student goes:

SELECT idProgram, MAX(Semestre) FROM Alumno, 
Materia a INNER JOIN Historial n ON a.idMateria = n.claveMateria 
GROUP BY idAlum; 

Which is wrong, because it puts me only one program instead of the respective one of each student.

I have other queries that give me indicators by career, however the advantage of them is that the data is in a single table (Student):

SELECT c.idPrograma as Licenciatura, sum(field(a.Estado_Alu,'CURSANDO')) as 
CURSANDO, sum(field(a.Estado_Alu,'BAJA TEMPORAL')) as BAJA_TEMPORAL,
sum(field(a.Estado_Alu,'BAJA ABSOLUTA')) as BAJA_ABSOLUTA,
sum(field(a.Estado_Alu,'EGRESADO')) as EGRESADO,
sum(field(a.Estado_Alu,'INTERCAMBIO')) as INTERCAMBIO,
count(a.idAlumno) as Total
FROM alumno a
join Programa c on a.idProgram=c.idPrograma
group by a.idProgram;

Which returns this table to me:

Thank you in advance for your support.

    
asked by Gael Rodriguez 24.05.2018 в 02:52
source

1 answer

1

I have no way to prove it at the moment, but it seems to me that this would generate what you are looking for:

SELECT Materia.idProgra, Historial.semes, count(Historial.idAlum) 
FROM Materia JOIN Historial ON Materia.IdMateria = Historial.claveMateria 
GROUP BY Materia.idProgra, Histrial.semes;
    
answered by 24.05.2018 в 03:41