检查两个日期字段中是否存在给定日期

时间:2012-10-09 11:18:01

标签: mysql

嗨朋友们,我不知道查询给定日期的查询在给定日期字段中不存在 在mysql .can任何人帮我发​​现我有两张桌子1.Marriage Hall和Booking hall id是大厅表中的主键和预订表中的外键。如何加入两个表。我的问题是1.在2013年1月15日之前找到可用的婚姻殿堂

booking_From      booking_to            
2012-10-12       2012-10-15         
2012-10-17       2012-10-19         

查看指定日期' 2012-10-12'并不存在于日期

之上

5 个答案:

答案 0 :(得分:1)

尝试

select * from <your_table> where '2012-10-12' between `From` and `to`


SQL Fiddle demo

答案 1 :(得分:0)

Here, we are find out date betwwen range of date or not.
If any record is exists then we count no of record is greater then o then date is exists otherwise date is not exists using case function :

   select (case when count(*) <=0 then 'Date is not exists' else 'Date is exists' end) as
     'exists' from given_date where `From` >= '2012-10-12' and  `to` <= '2012-10-12'

答案 2 :(得分:0)

select * from yourtable where `from`='2012-10-12' or `to`='2012-10-12';

答案 3 :(得分:0)

您可以使用OR条件运算符

SELECT * FROM yourTable WHERE FROM = YourDate OR To = YourDate

答案 4 :(得分:0)

SELECT 
  CASE DoesExist
    WHEN 1 THEN 'Exists'
    ELSE 'Doesnt Exist'
  END AS 'Exists or not?'
FROM
(
    SELECT 1 AS DoesExist
    FROM tAble
    WHERE EXISTS 
    (
         SELECT Date 
         FROM Table WHERE `FROM` >= '20121012' AND `To` <= '20121012'
    )
) t