I would like a query to get errors and hits from a particular student from the following table below:
To get to the desired result you can create a query
grouped by matricula_aluno
and use the COUNT
function together with a CASE
by testing the acertou
column:
SELECT r.matricula_aluno,
COUNT(CASE WHEN acertou THEN 1 END) AS acertos,
COUNT(CASE WHEN NOT acertou THEN 1 END) AS erros
FROM realizacao r
GROUP BY r.matricula_aluno
See working in SQL Fiddle.