判断一个两个时间段是否有交集,在很多地方都用到。电影院的售票系统,智能一点的,他在你购买第二张电影票时,判断两张电影票是否有时间冲突,等等。
怎么比较两个时间段呢?若有a时间点到b点和c点到d点的两个时间段。
则,只要比较a与d以及b与c的大小即可
a>d||b<c
如果上面的条件成立,则表明没有交集,
select t.startDate,t.endDate from PersonMovie t where t.startDate>‘20180101’ or t.endDate< ‘20171201’;
或者
select t.startDate,t.endDate from PersonMovie t where t.startDate>‘20180101’
union all
select t.startDate,t.endDate from PersonMovie t where t.endDate< ‘20171201’;
a<d && b>c 必有交集
select t.startDate,t.endDate from personmovice t where t.startDatef<‘20180101’ and t.endDatef> ‘20171201’;
作者:一木剑
来源:优快云
原文:https://blog.youkuaiyun.com/qq_34226365/article/details/80681240
版权声明:本文为博主原创文章,转载请附上博文链接!