mysql - Check if a client appears more than once in a table -
sso couldn't express need in title. i'm new mysql first of all, sql table i'm currenly using http://dl.dropbox.com/u/37057843/p2_scripts.sql
i'll explain briefly: need clients more once in (the) hotel , @ least once in every type of room. (check explanation of tables below)
these tables:
- reservas (reservations), contains id of reservation (id), id of client (idcliente) reserved , room number (idhabita).
- clientes, client table contains id, name (nombre), surname (apellido), address , phone number (those last 2 aren't used)
- habitaciones (rooms) contains room number (id), size in m2 (superficie), several things don't matter , lastly id of price (idprecio).
- precios (prices), contains id of entry, type of room (tipo) , price (precio). value of tipo can 'individual' or 'double'. individual or double room.
so basically,
- reservas.idcliente = clientes.id
- reservas.idhabita = habitaciones.id
- habitaciones.precio = precio.id
and mentioned earlier, need clients @ least once in every type of room, once or more in individual room , once or more in double room.
i know kinda bad explained don't know how explain better, sorry that.
i'm using query @ moment people (names, surnames & room nr) in individual rooms
select c.nombre, c.apellidos, r.idhabita clientes c, reservas r, precios p, habitaciones h r.idcliente = c.id , r.idhabita = h.id , h.idprecio = p.id , p.tipo 'individual' and know have type of subquery check if p.tipo 'double' well, don't working. clients query returns same ones in double rooms well. in fact, these ones ever in individual room. need query check in double rooms well.
thanks in advance reading!
to clients "that @ least once in every type of room", join clients table associated reservations , group results client—you want groups have same number of distinct room types there in room types table, can expressed in having clause:
select c.* clientes c join reservas r on r.idcliente = c.id join habitaciones h on r.idhabita = h.id join precios p on h.idprecio = p.id group c.id having count(distinct p.tipo) = ( select count(distinct tipo) precios ) see on sqlfiddle.
Comments
Post a Comment