douzhi2760 2016-10-20 06:25
浏览 31

如何从db获取记录?

I worked in travel CRS protal. for hotel booking i want to block hotel depends on the cutoff dates.

 SELECT * FROM (`crs_service_supplier_details` as crs) JOIN `crs_service_room_type_detail` as Room ON `crs`.`service_apartment_id`=`Room`.`service_id` JOIN `crs_room_type` as crt ON `Room`.`room_type_id`=`crt`.`room_type_id` JOIN `crs_service_off_dates` as ccod ON `crs`.`service_apartment_id`=`ccod`.`co_service` WHERE `crs`.`city` like '%Chennai%' AND ('2016-10-27' NOT between ccod.cut_off_from AND ccod.cut_off_from) AND ('2016-10-28' NOT between ccod.cut_off_to AND ccod.cut_off_to) AND `Room`.`edate` > '2016-10-27' GROUP BY `crs`.`service_apartment_id`

this is the query but the problem was in cut had two days

co_id   co_service  cut_off_from    cut_off_to  cut_off_release_days cut_off
1       1       2016-10-20      2016-10-22          0               2016-10-20
2       1       2016-10-27      2016-10-28          0               2016-10-28

if i searched between 2016-10-20 and 2016-10-22 it get the "2016-10-27 and 2016-10-28" and show the result.

if i searched between 2016-10-27 and 2016-10-28 it get the "2016-10-20 and 2016-10-22" and show the result. it wont block any where of the system. please give some idea to solve this?

  • 写回答

1条回答 默认 最新

  • doukuizuo1795 2016-10-20 06:35
    关注

    May be your query is not right. May be this will help, just change in BETWEEN logic:

    AND ('2016-10-27' NOT BETWEEN ccod.cut_off_from AND ccod.cut_off_to)
    AND ('2016-10-28' NOT BETWEEN ccod.cut_off_to AND ccod.cut_off_from)
    

    use the above.

    The original code with BETWEEN doesn`t make sense:

    AND ('2016-10-27' NOT BETWEEN ccod.cut_off_from AND ccod.cut_off_from)
    AND ('2016-10-28' NOT BETWEEN ccod.cut_off_to AND ccod.cut_off_to)
    

    Because it is making between on the same column.

    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)