Hello, in my select I need to find the average service time (TMA) between two BIGINT format columns:
Date: DtBegin and DtEnd
Hello, in my select I need to find the average service time (TMA) between two BIGINT format columns:
Date: DtBegin and DtEnd
It would be a conversion to DateTime with str_to_date , then # for an integer value and a division by 2 that would be the average of the result:
SELECT dtEnd, dtEnd,
((UNIX_TIMESTAMP(dtEnd) - UNIX_TIMESTAMP(dtBegin)) / 2) media
from tempo tempo
The average in this case has its output in seconds like 30 seconds, 19 seconds, and so on.
References:
Use the FROM_UNIXTIME
function to convert to date and to make a difference to the TIMESTAMPDIFF
function.
SELECT
DtBegin,
DtEnd,
TIMESTAMPDIFF(SECOND,FROM_UNIXTIME(DtBegin),FROM_UNIXTIME(DtEnd)) AS TempoSegundos
from Interaction
Friend! You are not able to use TIMESTAM
because your data type is DATETIME
. That is, your query is looking for one type of data being in the database is another.