MySQL的SQL日期范围查询总结

  • Post author:
  • Post category:mysql


  • 过去一小时
SELECT * FROM table WHERE user_time BETWEEN DATE_SUB(NOW(),INTERVAL 1 HOUR) and NOW()
  • 当天到目前为止
SELECT * FROM table WHERE DATE(user_time) = curdate()
  • 昨天
SELECT * FROM table WHERE DATEDIFF(user_time,NOW()) = -1
  • 过去7,不包含今天
SELECT * FROM table WHERE user_time >= CURDATE() - INTERVAL 7 DAY AND user_time < curdate()



版权声明:本文为hualingkai11原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。