༒࿈背༙྇景༙྇:࿈༒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');
完美解决问题!
开发要求,获取当月佣金,主要卡在了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');
完美解决问题!
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/8627/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
评论列表