MySQL- dates between dates -
this question has answer here:
- mysql: select data between 2 dates 6 answers
i have question share you..
say, have site hotel reservations , have 2 fields datein , dateout.
well, see if dates between datein , dateout free...
i want using mysql..
like that:
select hotelname hotel ..
(all dates >= datein , dates<=dateout free)
--> how can in mysql?
thank in advance!! think not difficult can't find it...
if field free bool (tinyint), try this:
select * ( select `hotelname`, min(`available`) _available `hotels` dbdate between 20130507 , 20130511 group `hotelname`)a _available;
the above query gave both hotels test result, when change 20130507 20130503, return amsterdam hotel.
with test table:
create table `hotels` ( `hotelname` varchar(20) default null, `dbdate` int(11) default null, `available` tinyint(1) default null ) engine=myisam default charset=latin1; /*data table `hotels` */ insert `hotels`(`hotelname`,`dbdate`,`available`) values ('amsterdam hotel',20130503,1),('amsterdam hotel',20130504,1),('amsterdam hotel',20130505,1),('amsterdam hotel',20130506,1),('amsterdam hotel',20130507,1),('amsterdam hotel',20130508,1),('amsterdam hotel',20130509,1),('amsterdam hotel',201305010,1),('amsterdam hotel',201305011,1),('amsterdam hotel',201305012,1),('utrecht hotel',20130503,0),('utrecht hotel',20130504,0),('utrecht hotel',20130505,0),('utrecht hotel',20130506,0),('utrecht hotel',20130507,1),('utrecht hotel',20130508,1),('utrecht hotel',20130509,1),('utrecht hotel',201305010,1),('utrecht hotel',201305011,1),('utrecht hotel',201305012,0);
Comments
Post a Comment