Mysql query intervals

3

I need to mount a select, where I need to display the results outside of a range of code. For example: I have code 2 as a start and code 6 as an end, how could I not display codes 3, 4 and 5 and only display code 1 and from 5 onwards? Only with SQL is it possible?

With this select I can not display the starting and ending code, but still showing what's between them

SELECT h.cod, h.horario FROM horarios h 
WHERE h.cod NOT IN (SELECT cod_hora_saida FROM reservas) AND 
      h.cod NOT IN (SELECT cod_hora_prevista FROM reservas) 
ORDER BY h.cod ASC

UPDATE

I keep trying, but I still can not get the result I need. The tables I use are the 2 below

TheresultI'mtryingisthis,usingthetablesbelowasanexample:

6:00p.m.06:3007:0007:308o'clock08:3009:0009:3010:00am1PM13:3014:0014:3015:0018:0018:307pm

LASTUPDATE

Itestedtheunionallfunction,withareservationworkedout,butifithasmorethanoneonthesamedayitnolongerworks.Suggestions?

select * from horarios where cod < 20 union all select * from horarios where cod > 25
    
asked by anonymous 01.12.2015 / 14:40

1 answer

1

If someone had a similar problem, the solution was this:

SELECT * FROM HORARIO H
 WHERE NOT EXISTS (
SELECT * FROM RESERVA R
 WHERE H.COD BETWEEN R.SAIDA AND R.RETORNO-1)
ORDER BY H.COD

Thank you

    
02.12.2015 / 14:43