按日期范围检索数据

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

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

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

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

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

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

erhoui1w

erhoui1w1#

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

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

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

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

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

相关问题