原文地址: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