滿實用的 sql,決定收錄一下。
Use for a date three days ago:
WHERE t.date >= DATE_ADD(CURDATE(), INTERVAL -3 DAY);
Check the DATE_ADD documentation.
Or you can use:
WHERE t.date >= ( CURDATE() - INTERVAL 3 DAY )
Make use of the DATE_SUB() and Now() functions:
select count(*) as cnt
from log
where date >= DATE_SUB(NOW(),INTERVAL 1 HOUR);