【问题标题】:How to find count of conflicted date如何查找冲突日期的计数
【发布时间】:2012-05-31 10:55:18
【问题描述】:

我想限制用户在下表中已经存在的开始日期和结束日期之间输入开始日期和结束日期。

例如:用户尝试插入日期开始日期 2012 年 2 月 6 日和结束日期 2012 年 4 月 6 日;此日期介于下表中的事件 e2 之间,因此不允许用户插入它。

 ------------------------------------------------------------------------
 id               event               startdate    enddate
 ------------------------------------------------------------------------
 11                e1                 31/5/2012    1/6/2012
 12                e2                 1/6/2012     4/6/2012
 13                e3                 5/6/2012     6/6/2012
 14                e4                 15/6/2012    16/6/2012

我想计算那些与其他事件发生冲突的事件。

【问题讨论】:

    标签: database sqlite count conflict


    【解决方案1】:
    select tbl.startdate, count(tbl.startdate)
    from YourTable tbl
    where 
    exists(select * from YourTable tbl2 where ((tbl2.startdate>=tbl.startdate AND tbl2.startdate<=tbl.enddate) OR (tbl2.enddate>=tbl.startdate AND tbl2.enddate<=tbl.enddate)))
    group by tbl.startdate
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-01
      • 2011-02-12
      • 1970-01-01
      • 2020-02-03
      • 2018-07-01
      • 2019-02-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多