0

I have two tables in MySQL - tickets and ticket_updates

With the following structure:

tickets

  • sequence
  • ticketnumber
  • datetime

ticket_updates

  • sequence
  • ticketnumber
  • datetime

the relationship is: tickets.ticketnumber = ticket_updates.ticketnumber

i want to find out the Average response time for a certain day based on when rows are inserted into ticket_updates

I tried this Query:

SELECT avg(response_seconds) as s FROM 
    (SELECT time_to_sec(timediff(min(u.datetime), u.datetime)) AS response_seconds 
    FROM tickets t JOIN ticket_updates u ON t.ticketnumber = u.ticketnumber 
    WHERE u.type = 'update' and t.customer = 'Y' and DATE(u.datetime) = '2016-04-18' 
    GROUP BY t.ticketnumber) 
    AS r 

but everytime, its returning 0.000

1 Answer 1

1

I think the problem is with:

(SELECT time_to_sec(timediff(min(u.datetime), u.datetime)) AS response_seconds

which returns 0 on my console. Try with:

( select time_to_sec( timediff( from_unixtime( floor( UNIX_TIMESTAMP(u.datetime)/60 )*60 ), u.datetime) ) ) as response_seconds;

like

SELECT avg(response_seconds) as s FROM 
    ( select time_to_sec( timediff( from_unixtime( floor( UNIX_TIMESTAMP(u.datetime)/60 )*60 ), u.datetime) ) ) as response_seconds 
    FROM tickets t JOIN ticket_updates u ON t.ticketnumber = u.ticketnumber 
    WHERE u.type = 'update' and t.customer = 'Y' and DATE(u.datetime) = '2016-04-18' 
    GROUP BY t.ticketnumber) 
    AS r 
Sign up to request clarification or add additional context in comments.

3 Comments

thats now just returning NULL
Yeah, on my machine also returns NULL, I totally rewrote my answer, with a different solution
thats returning a syntax error #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM tickets t JOIN ticket_updates u ON t.ticketnumber = u.ticketnumber WHE' at line 3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.