SQL 两个日期不大于指定日期时显示的查询

SQL Query to display if two dates is not bigger than a specified date

如果 created_at 和 deleted_at 都大于指定日期,我如何 select 大于指定日期(最后请求日期)的数据并排除?

例如 last_requested_date 是“2017-03-09 15:41:00”。 然后,我想显示在“2017-03-09 15:41:00”之后 created/updated/deleted 的国家/地区。但我不想显示在 last_requested_date 之后创建然后删除的国家(例如 created_at '2017-03-09 15:41:01' 和 deleted_at '2017 -03-09 15:41:02')

我的代码是这样的:

SELECT * FROM countries
WHERE (created_at > '2017-03-09 15:41:00' OR
      updated_at > '2017-03-09 15:41:00' OR
      deleted_at > '2017-03-09 15:41:00') AND
      NOT (created_at > '2017-03-09 15:41:00' AND deleted_at > '2017-03-09 15:41:00')

但输出不是我预期的。任何解决方案将不胜感激!谢谢

 SELECT * FROM countries
 WHERE (created_at > '2017-03-09 15:41:00' OR
  updated_at > '2017-03-09 15:41:00' OR
  deleted_at > '2017-03-09 15:41:00') AND id NOT IN
  (SELECT id FROM countries where created_at > '2017-03-09 15:41:00' AND deleted_at > '2017-03-09 15:41:00')

检查这个。

        SELECT * FROM countries
        WHERE (created_at > '2017-03-09 15:41:00' OR
              updated_at > '2017-03-09 15:41:00' OR
              deleted_at > '2017-03-09 15:41:00') AND

        datediff(SECOND,created_at, deleted_at) > 60

这里我们检查两个日期(created_at和deleted_at)之间的差异必须大于60秒,您可以根据需要进行编辑。

如果我对您的要求理解正确,那么您的查询非常接近于产生期望的结果。您可能需要再添加一个条件来检查创建日期和删除日期之间的日期差异,以避免今天自行创建和删除的国家/地区。

SELECT * 
FROM countries
WHERE (created_at > '2017-03-09 15:41:00' OR
       updated_at > '2017-03-09 15:41:00' OR
       deleted_at > '2017-03-09 15:41:00'
      ) AND (created_at > '2017-03-09 15:41:00' AND 
             deleted_at > '2017-03-09 15:41:00' AND 
             DATEDIFF(created_at,deleted_at) > 0)