SQL-Count for each id

Asked

Viewed 86 times

0

I want to show all student table records - name and number - and then in the right column, show attendance percentage. Let’s see:

SELECT nome, numero, (
(

SELECT COUNT(aluno.numero)
FROM aluno
JOIN aula ON aluno.id_aula_aluno = aula.id_aula 
WHERE aula.id_uc_aula =4
AND aula.id_professor_aula =1 AND aluno.numero=11111) / 

(SELECT COUNT( aula.id_uc_aula )
FROM aula
WHERE aula.id_uc_aula =4
AND aula.id_professor_aula =1 )
) AS Percentagem

FROM aluno
JOIN aula
WHERE aula.id_uc_aula =4
AND aula.id_professor_aula =1
AND aluno.id_aula_aluno = aula.id_aula

That is, in the second select only this to be accounted for a student and I wanted for each id automatically. The division this between the two select.

  • What id_uc_aula means?

  • 1

    I’m not sure what you’re still wanting to do, two more important things to see, first in your second select you have one COUNT( aula.id_uc_aula ) and then WHERE aula.id_uc_aula =4 This at most ira returns 1 in your Count 2º There is a need for you to check if the second select does not return a value null , if this happens will return a split error see here

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.