Hi,
First of all you should get the ticket_id (internal key on database, not the public TicketID) from ost_ticket table. You could get it with a sql sentence like this:
SELECT ticket_id from ost_ticket WHERE ticketID = (your target public TICKET ID)
Once done you should obtain the first two responses for that ticket_id at ost_ticket_response table. First one will be the original message and the second one will be the first response. You could do it with another SQL sentence like this:
SELECT TOP 2 from ost_ticket_response WHERE ticket_id = (ticket_id obtained in the last step) ORDER BY created ASC
NOTE: If you're using MySQL your sql sentence will be:
SELECT * FROM ost_ticket_response WHERE ticket_id = (ticket_id obtained in the last step) ORDER BY created ASC LIMIT 2
When you have got this two records you can calculate the time between both records by comparing the created date. My suggestion is to use DATEDIFF function