原文地址:https://blog.csdn.net/sinat_19569023/article/details/50417273

SQL博大精深

TO_DAYS函数 返回一个天数! 啊哈?什么天数? 从年份0开始的天数 

比如:

mysql> SELECT TO_DAYS(‘1997-10-07′);

结果  729669
就是从0年开始 到1997年10月7号之间的天数

理解这个之后那么一切就变得拉么简单!有一张表!lito表 有一个字段 create_time  类型 datetime  

如果要查询当前表中昨天的数据那么

select * from lito where to_days(now())-to_days(create_time)<1

前天的?那就是
select * from lito where to_days(now())-to_days(create_time)<2 and to_days(now())-to_days(create_time)>1

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2021-09-03
  • 2021-05-27
猜你喜欢
  • 2022-02-03
  • 2022-12-23
  • 2022-12-23
  • 2021-08-18
  • 2021-08-11
  • 2022-12-23
  • 2021-12-12
相关资源
相似解决方案