Postgresql: Catch amount of errors and hits

Asked

Viewed 43 times

0

I need a query to get amount of errors and hits from this table. Dabela com dados

1 answer

3


Something like that:

SELECT t.acertou,
       COUNT(1)
  FROM tabela t
 GROUP BY t.acertou

If you wanted to show as just a record, you can use subquery:

SELECT (SELECT COUNT(1)
          FROM tabela t
         WHERE t.acertou) AS acertos,
       (SELECT COUNT(1)
          FROM tabela t
         WHERE NOT t.acertou) AS erros
  • show.... worked here... but how do I catch each one in a column?

  • 1

    @Thiagocunha depends, you want to filter by student or how you want to do it? All at once?

  • needed only 2 columns... 1 showing the amount of hits, and another, with the amount of errors...

  • 1

    @Thiagocunha changed the answer based on his doubt

  • TOP! Thanks even! It worked perfectly!

  • Just one more question based on your doubt about the execution. If I want to pick grouped per student? That is, show: qtd_erros_student, qtd_student rights_student

  • 1

    @Thiagocunha then the answer would change radically. If you want to ask another question with this doubt I can come up with a query that answers

  • https://answall.com/questions/299105/query-para-pegar-erros-e-acertos-de-um-aluno

Show 3 more comments

Browser other questions tagged

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