简体   繁体   English

MySQL查询如何显示相反的结果

[英]MySQL Query how to show opposite results

im using this SQL Query in my PHP code: 我在我的PHP代码中使用此SQL查询:

SELECT
   *
FROM
   maintenance
WHERE
   from_date <= DATE_ADD(NOW(), INTERVAL 5 DAY)
   AND to_date >= DATE(NOW())
ORDER BY 
   from_date ASC

its showing rows 5 days before the from_date field. 其显示在from_date字段之前5天的行。 so basically rows where the maintenance is still pending as the date hasn't passed yet. 因此,基本上,由于日期尚未过去,因此维护仍在等待处理的行。

i want to be able show the oposite results. 我希望能够显示相反的结果。 so all the rows where the maintenance is completed if possible? 因此,如果可能的话,所有完成维护的行?

You can exclude these results: 您可以排除以下结果:

SELECT
   * 
FROM
   maintenance
WHERE id NOT IN (SELECT
                   id
                 FROM
                   maintenance
                 WHERE
                   from_date <= DATE_ADD(NOW(), INTERVAL 5 DAY)
                   AND to_date >= DATE(NOW())
                 )
ORDER BY 
   from_date ASC

Or simply, negate the condition in your original query. 或者简单地,否定原始查询中的条件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM