0

Hi friends just i don't know the query to check given date doesn't exists given date field in mysql .can any one help me to find out i have two table 1.Marriage Hall and Booking hall id is the primary key in hall table and foreign key in booking table .how to join two table . my question is 1.Retrieve the available marriage halls for the date 01-15-2013

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

to check the given date '2012-10-12' doesn't exists above the date

4

5 回答 5

1

尝试

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


SQL Fiddle 演示

于 2012-10-09T11:21:48.127 回答
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'
于 2012-10-09T11:21:14.400 回答
0
select * from yourtable where `from`='2012-10-12' or `to`='2012-10-12';
于 2012-10-09T11:22:25.737 回答
0

您将使用 OR 条件运算符作为

SELECT * FROM yourTable WHERE FROM = YourDate OR To = YourDate
于 2012-10-09T11:22:28.797 回答
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
于 2012-10-09T11:22:36.693 回答