2
I’m having a problem to perform a specific filter in a query in Mysql.
I am building a search system where I have the following tables:
- Questionnaires: with the name of the questionarios
- Questions: containing the questions in the questionnaire, with
foreign key
pointing to the questionnaire table - Answers: containing the answers to each question, with the
foreign key
pointing to questions - Tokens: Information on who replied
- Answers Given: Contains the answers given by each person.
I have the following structure:
[Tabela Fichas]
- ID
- created_at
- latitude
- longitude
[Tabela Respostas dadas]
- id
- ficha_id
- resposta_id
- pergunta_id
I need a consultation that returns the amount of respostas_id
according to a specific question.
For example, I need to know who answered "23" in the field resposta_id
when pergunta_id = "81"
, answered the other questions.
I’ve been hitting my head on this for days, but I’m not getting it. I even thought about creating a view that organized the data so that each question was a column and the answers were the lines, but also I could not.
select count(*) from respostas_dadas where resposta_id = id_da_resposta_a_contar
, try this.– Edilson
If I understand correctly you want to know the other answers of who selected answer 23 from question 81, is that it? Another question, when the user answers the entire questionnaire, is only recorded a record of
ficha
for him?– marcusagm
Do you want to get a certain answer to a question? That’s it?
– Pedro Camara Junior
Oops, thank you. That’s right. And when the person answers the entire questionnaire, a record is saved in the table tokens and the answers are saved in the table answered.
– Jean K. Santos