【问题标题】:Select all data from current month and next month from MYSQL database从MYSQL数据库中选择当前月份和下个月的所有数据
【发布时间】:2021-03-26 10:40:20
【问题描述】:

我不知道如何进行这项工作,我尝试了很多不同的方法,但我没有找到有效的方法,所以请帮助我:)

我当前的查询如下:

SELECT * FROM `police` 
WHERE skadenca BETWEEN DATE(now()) 
  AND adddate(current_date, interval +1 month) 
  AND produkt LIKE 'avto' 
  AND statusobnove=0 AND status=0

就像我已经说过的,我想获取当前月份和下个月的所有数据。

ty

【问题讨论】:

  • 当前日历月还是 +/- 30 天?

标签: mysql sql datetime date-arithmetic


【解决方案1】:

理解您的问题的方法不止一种。

在当前日期和下个月月底之间将表述为:

where 
    skadenca >= current_date 
    and skadenca < date_format(current_date, '%Y-%m-01') + interval 2 month

当前月初和下个月月底之间将是:

where 
    skadenca >= date_format(current_date, '%Y-%m-01')
    and skadenca < date_format(current_date, '%Y-%m-01') + interval 2 month

在当前日期和提前一个月之间将是:

where 
    skadenca >= current_date
    and skadenca < current_date + interval 1 month

【讨论】:

  • 嘿,感谢您的快速回复:) 看起来我还不够清楚..所以我有大约 100 行,大约 60 行来自 12 月(不同的日子),大约 40 行是在一月(不同的日子) )...所以我想从两个月里把它们全部拿走
  • @user2352034:第二个表达式就是这样做的。
  • 我试过了,但它只抓取了 12 月的行
  • @user2352034:我的错。固定。
  • 现在像奔驰一样工作 :) 谢谢你uuuuuuuuuuuuuu
猜你喜欢
  • 1970-01-01
  • 2018-06-18
  • 1970-01-01
  • 1970-01-01
  • 2015-04-09
  • 1970-01-01
  • 2014-12-30
  • 2021-11-24
  • 1970-01-01
相关资源
最近更新 更多