Basic report through SQL

-2

Good afternoon, I am doing an evaluation questionnaire system, where you have several questionnaires with several questions that refer to a questionnaire, which can be opened or closed.

In the response table where I'll pull reports, it works with the following fields: ID / RESTRICT ID / RESPONDENT / QUESTION ID / QUESTIONNAIRE / QUESTIONNAIRE / TYPE / RESPONSE

What I want is the following, to get the amount of answers with value 'Very Good', 'Good', 'Bad,' Very Bad ', Example:

Question / Answer / Quantity

Question 1 - Very good - 3

Question 1 - Good - 4

Question 2 - Very good - 5

Question 2 - Good - 2

    
asked by anonymous 30.05.2018 / 21:34

1 answer

0

I imagine that each row in this table has an answer to a question for a person (all 1: 1: 1), and that it is denormalized to (ID_PERGUNTA, QUESTION).

If this is the case, your SQL query should look like this:

SELECT Pergunta, Resposta, COUNT(*) AS Quantidade
FROM <tabela>
GROUP BY Pergunta, Resposta
ORDER BY 1, 2
    
30.05.2018 / 21:54