STR_TO_DATE(str,format) 这是DATE_FORMAT()函数的反函数。它需要一个字符串str和一个格式字符串格式。STR_TO_DATE()返回一个DATETIME值。 开发要求,获取当月佣金,主要卡在了sql对datetime 类型的判断 先后用过4种方法如下 1.select sum('price') from rrr_order_level where active_time < "2015-09-30 00:00:00"; 2.select sum('price') from rrr_order_level where timestampdiff(hour,'2008-08-08 12:00:00','2008-08-08 00:00:00') > 0 3.select sum('price') from rrr_order_level where active_time < '$EndDate' and active_time > '$BeginDate'" 4.select sum('price') from rrr_order_level where active_time between '2015-09-01 00:00:00' and '2015-09-30 00:00:00'; 数据库如上 分析错误,mysql不知道对应的年月日,无法比较,采用 select sum(price) from rrr_order_level where active_time >= STR_TO_DATE('2015-09-01 00:00:00','%Y-%m-%d %H:%i:%s') and active_time <= STR_TO_DATE('2015-09-30 00:00:00','%Y-%m-%d %H:%i:%s'); 完美解决问题! (责任编辑:好模板) |