mysql5日期类型datetime查询范围值

1.DATE_FORMAT函数

SELECT a.create_time FROM account_log a 
WHERE  a.create_time >=  DATE_FORMAT(2014-05-10 00:00:00,%Y-%m-%d %H:%i:%s)
             AND a.create_time <= DATE_FORMAT(2014-05-25 23:59:59,%Y-%m-%d %H:%i:%s)    

2.STR_TO_DATE函数

SELECT a.create_time FROM account_log a 
WHERE  a.create_time >=  STR_TO_DATE(2014-05-10 00:00:00,%Y-%m-%d %H:%i:%s)
             AND a.create_time <= STR_TO_DATE(2014-05-25 23:59:59,%Y-%m-%d %H:%i:%s)

3.直接比较

SELECT a.create_time,a.order_no FROM account_log a 
WHERE  a.create_time >=  2014-05-10 00:00:00
             AND a.create_time <= 2014-05-25 23:59:59

mysql5日期类型datetime查询范围值,布布扣,bubuko.com

mysql5日期类型datetime查询范围值

上一篇:SQL Server 2012内部原理及故障排除(专栏)


下一篇:MySQL索引原理及慢查询优化-来自美团网的技术blog(写的深入浅出)