add absence records

1

I have the following tables in a school attendance system:

INASISTENCIA(idinasistencia,fecha,idtipoinassitencia,idalumno);
TIPOINASISTENCIA(idtipoinasistencia,valor);

How can I count the total value of a student's absence within a quarter? In other words, from March to May, for example, when the notebook is put together, the total number of absences that you have is placed.

Try the following:

SELECT   SUM(valor) as total 
FROM     tipoinasistencia 
WHERE    tipoinasistencia.idtipoinasistencia 
    IN ( SELECT idtipoinasistencia 
         FROM inasistencia 
         WHERE fecha BETWEEN '2016-08-08' AND '2016-09-17' 
           AND idalumno=3);

But it seems to be a one time account for each type of absence and not for each time an absence appears.

What can I do?

    
asked by Caruso 17.09.2016 в 22:24
source

1 answer

1

It's done with a simple GROUP BY

SELECT SUM(valor) as total,tipoinasistencia.idtipoinasistencia FROM
tipoinasistencia 
INNER JOIN inasistencia ON inasistencia.idtipoinasistencia = tipoinasistencia.idtipoinasistencia
WHERE fecha BETWEEN '2016-08-08' AND '2016-09-17' AND idalumno=3 GROUP BY tipoinasistencia.idtipoinasistencia

That would be my solution to your problem, although it would help me more to see the structure of your tables, to help you better

    
answered by 17.09.2016 / 22:32
source