I have a table which contains 2 columns date_picked_begin
and date_picked
and there will be multiple rows which contain a date in each.
How do I use TIMESTAMPDIFF
to get the difference in seconds between the dates in all rows of data.
I have tried the following query but it only returns the difference in seconds from the first row. (It's the alias total_picking_waiting_time which is trying to get the total time).
SELECT COUNT(pi.pi_id) AS num_picking_waiting_time,
AVG(TIMESTAMPDIFF(SECOND, pi.date_picked_begin, pi.date_picked)) AS average_picking_waiting_time,
TIMESTAMPDIFF(SECOND, pi.date_picked_begin, pi.date_picked) AS total_picking_waiting_time
FROM (SELECT pi_id, type, date_picked_begin, date_picked, picker FROM pickwave_items) as pi
WHERE pi.type = 'Picking (Waiting Time)' AND DATE(pi.date_picked) = '2017-02-25' AND pi.picker = 1
Also, I have been assuming that this query was getting the average time between the 2 dates in all rows. Is this the case? With it not returning the total time as I expected I am now thinking that it isn't.
Thank you