3
I have a question when it comes time to mount a query.
I’ll set up a fictional scenario to demonstrate.
I have the table quantidadeQuestoes
with the fields:
- cod_nivel
- cod_categoria
- cod_difficulty
- amount
And I have the table questoes
with the fields:
- cod_nivel
- cod_categoria
- cod_difficulty
- description
My question is. How to get from the table questoes
the quantity specified in the field quantidade
table quantidadeQuestoes
where other fields are matched.
With my current query I am taking all items and not just the specified amount in the quantity field, which is what I need:
SELECT
qt.descricao
FROM
quantidadeQuestoes qq
INNER JOIN
questoes qt ON
qq.cod_nivel = qt.cod_nivel AND
qq.cod_categoria = qt.cod_categoria AND
qq.cod_dificuldade = qt.cod_dificuldade
It is for me to put together a test that contains so many questions of a level + category + difficulty.
Joaopaulo, the table quantityTuestoes stores how many questions there are for the key (cod_nivel, cod_categoria and cod_dificuldade)?
– cantoni
I can’t remember if this syntax is possible, but you’ve tried putting a
top qq.quantidade
in the query?– Luis Henrique
@Cantoni did not understand your question.
– Joao Paulo
I couldn’t figure out what part of the query would fit this top @Luishenrique. Where I tried SQL did not allow
– Joao Paulo
My question is about your model. I am understanding that the table quantityTheses stores the amount of questions for the same cod_nivel, cod_categoria and cod_dificuldade. Already the table questions stores the questions themselves. I understood right?
– cantoni
Exactly @Cantoni.
– Joao Paulo
Okay, I’m going to post an answer here. Anyway, from the template posted, I’m not seeing any reason for the existence of the table quantityThese. In the answer I explain.
– cantoni
If the table quantityTheses simply stores as many records of questions of the other table I don’t understand what you want. What I had understood is that to create a proof creates records in the table quantityTuestos specifying the level, category and difficulty and the number of questions desired.
– Luis Henrique
You got it right @Luishenrique. The number of questions is already pre-defined. From it I mount a test with the amount of questions specified with level + category + difficulty
– Joao Paulo
You tried to make
select top qq.quantidade qt.descricao from...
? Anyway this would always take the same questions (the first N based on the other filters), I think the system to capture the issues and generate the evidence could be reworked and not treated in the database.– Luis Henrique