【问题标题】:How can i combine two columns to filter on using between?我如何结合两列来过滤在两者之间使用?
【发布时间】:2021-07-23 00:27:14
【问题描述】:

我的数据中有两列,分别称为年和月。我只想提取日期大于 > 201802 且小于 202103 的数据。

select 


* 

from table 

where year+month between 201802 and 202103.. 

是我想要的。我的两列都是整数。我该怎么做?

【问题讨论】:

    标签: mysql sql filter


    【解决方案1】:

    你可以使用算术:

    where year * 100 + month between 201802 and 202103
    

    或者,您可以使用元组(但不能使用 between):

    where (year, month) >= (2018, 02) and
          (year, month) <= (2021, 03)
    

    【讨论】:

      猜你喜欢
      • 2016-04-05
      • 2014-01-14
      • 2018-02-14
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 2021-02-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多