按日期范围检索数据

laik7k3q  于 2021-06-15  发布在  Mysql
关注(0)|答案(1)|浏览(295)

这是我能够得到2018-12-12日期数据的代码。

SELECT COUNT(`table`.`ID`), `table`.`number_Of_Car`
FROM `company`.`table` 
WHERE `table`.`location` <> '' AND `table`.`location` LIKE('%2017-12-12%') 
Group by ...

不过,我尝试了以下方法:

SELECT COUNT(`table`.`ID`), `table`.`number_Of_Car`
FROM `company`.`table` 
WHERE `table`.`location` <> '' AND `table`.`location` BETWEEN('%2018-12-12%') AND ('%2018-12-13%') 
Group by ...

有没有办法让我做以下工作?

3phpmpom

3phpmpom1#

如果需要特定日期的数据,请使用:

where t.column >= '2017-12-12' and
      t.column < '2017-12-13'

如果您想要多个日期,只需扩展范围:

where t.column >= '2018-12-12' and
      t.column < '2018-12-14'

不要使用 like 日期。我不明白为什么一个专栏叫 location 包含日期。

相关问题