将两个日期类型直接相减,如果两个时间是跨时、分的情况下,得到的时间差不对。
问题实例
SQL:
SELECT sfec.last_update_date AS `Es Last Update Date`, si.last_update_date AS `Item Last Update Date`, (sfec.last_update_date - si.last_update_date) AS `Cost` FROM scux_fr_event_consume sfec, smdm_item si WHERE sfec.action = si.item_id AND sfec.consume_status = ‘success‘;
执行结果:
解决办法
SQL:
SELECT sfec.last_update_date AS `Es Last Update Date`, si.last_update_date AS `Item Last Update Date`, (UNIX_TIMESTAMP(sfec.last_update_date) - UNIX_TIMESTAMP(si.last_update_date)) AS `Cost` FROM scux_fr_event_consume sfec, smdm_item si WHERE sfec.action = si.item_id AND sfec.consume_status = ‘success‘;
执行结果: