This is the sample
season_dates table:
This is the sample check-in and check-out (
check_in_out) table:
This is the SQL query:
SELECT *, IF(`cio`.`out` > `sd`.`ends`,(DATEDIFF(`sd`.`starts`,`cio`.`in`) + DATEDIFF(`cio`.`out`,`sd`.`ends`)),DATEDIFF(`sd`.`starts`,`cio`.`in`)) AS `low`, IF(`cio`.`out` > `sd`.`ends`,(DATEDIFF(`cio`.`out`, `sd`.`starts`) - DATEDIFF(`cio`.`out`,`sd`.`ends`)), DATEDIFF(`cio`.`out`, `sd`.`starts`)) AS `high` FROM `check_in_out` AS `cio`, `season_dates` AS `sd` WHERE (`cio`.`in` >= `sd`.`starts` AND `cio`.`in` <= `sd`.`ends`) OR (`cio`.`out` >= `sd`.`starts` AND `cio`.`out` <= `sd`.`ends`)
This is the query result:
