SQL NOT BETWEEN query

后端 未结 2 387
天命终不由人
天命终不由人 2020-12-07 02:28

Thanks in advance for any advice or tips!

I have a booking table in a mysql database, table1. It contains a start date and a finish date. I have another

相关标签:
2条回答
  • 2020-12-07 03:01

    Something like this then?

    select table2.testfield
    FROM table2, table1
    WHERE 
       table1.start > convert(datetime,'2011-02-24 18:00:00')
       or table1.finish < convert(datetime,'2011-02-24 18:00:00')
    
    0 讨论(0)
  • 2020-12-07 03:09

    This should work but should look something more like

    select table2.testfield
    FROM table2, table1
    WHERE table1.YourField = '2011-02-24 18:00:00' 
    AND
    NOT BETWEEN table1.start AND table1.finish
    

    This also presumes that your table1.start and table1.finish fields are of type DateTime. If they aren't you could try Casting the fields

    select table2.testfield
        FROM table2, table1
        WHERE table1.YourField = '2011-02-24 18:00:00' 
        AND
        NOT BETWEEN Cast(table1.start as DateTime) AND Cast(table1.finish As DateTime)
    

    Edit Looking at your question I realized that the date probably isn't a database value :) so your method should work but you may need to cast the string to a datetime.

    0 讨论(0)
提交回复
热议问题