I have some problems with a Query that I can't get out, the structure of the tables is the following:
child
child_id ----->CLAVE PRIMARIA
child_name
birth_date
gender
address
city
letters
letter_id --->Clave primaria
child_id ---->Clave ajena que referencia a la tabla child,child_id
arrival_date
number_toys
wished_toy
letter_id -->Clave primaria a su vez clave ajena con letter_id de letter
toy_id ---->Clave primaria a su ves clave ajena con toy_id de toy
toy
toy_id--->Clave primaria
toy_name
price
toy_type
manufacturer
Well, in the query I am asked to obtain the letters received where at least 3 toys with a price lower than 10 euros have been requested, the id_letter, child_name, birth_date and number of toys requested in the number_toys letter are requested
Well, the first part of the query is clear to me, first I take out the cards of the children who have requested at least 3 toys and I do it as follows
select l.letter_id,l.number_toys,h.child_name,h.birth_date
from letter l natural join child h
where l.number_toys >='3';
Well, I don't know how to continue with this query, how to relate to more joins to reach the toy table, which is where the price of the toys is stored, and tell it that the price must be less than 10.
What you need to do is a join to
wished_toy
ytoy
which limits to only toys that cost less than 10 euros.Then you group by cards and use the clause
having count(*) >= 3
to limit the result to those that include 3 or more toys that satisfy the filter described above.