sql - MySQL query with DATEDIFF -
i trying build query load records , specific date comparing 2 fields - start_time , end_date.
select start_time ,end_time ,datediff(end_time, start_time) diffdate my_tbl start_time >= '2015-04-27 00:00:00' , end_time <= '2015-04-28 00:00:00' , end_time >= '2015-04-27 00:00:00' , diffdate < 100 limit 1000;
unfortunately diffdate returns 0. ideal scenario calculate difference between start_time , end_time when inserting end_time cant make changes on database. doing wrong here? if diffdate working considered solution?
from condition in clause appears trying data same date, using datediff
same day result 0
mysql> select datediff('2015-04-27 12:00:00','2015-04-27 00:00:00') diff ; +------+ | diff | +------+ | 0 | +------+ 1 row in set (0.03 sec)
you may need other means of calculation perhaps using timestampdiff
mysql> select timestampdiff(minute ,'2015-04-27 00:00:00','2015-04-27 12:00:00') diff ; +------+ | diff | +------+ | 720 | +------+ 1 row in set (0.00 sec)
also using alias in clause not allowed have change having clause
select start_time ,end_time ,timestampdiff(minute,start_time,end_time) diffdate my_tbl start_time >= '2015-04-27 00:00:00' , end_time <= '2015-04-28 00:00:00' , end_time >= '2015-04-27 00:00:00' having diffdate < 100 limit 1000;
Comments
Post a Comment