mysql - Check response time on sent message - possible with using only SQL? -


i trying figure out general response time per. message. so, every time sender sends message receiver, how many seconds (think converting unix timestamp suitable solution, , dividing) went, before user responded.

i have table:

+--------------+----------+ |    field     |   type   | +--------------+----------+ | msg_id       | int(11)  | | msg_sender   | int(11)  | | msg_receiver | int(11)  | | msg_date     | datetime | | msg_message  | longtext | +--------------+----------+ 

i have tried hour figure out how put up, , solutions horrible long, complicated and/or inefficient, , made me wonder, if possible/most efficient via mysql.

maybe of point me in right direction.

select t1.*, min(t2.msg_date) response_date  mytable t1 join mytable t2        on t1.msg_sender=t2.msg_receiver , t2.msg_sender=t1.msg_receiver , t2.msg_date>t1.msg_date group t1.msg_sender,t1.msg_receiver,t1.msg_date  

for each message in t1 corresponding answers sent after t1 message , group them minimal response date (first answer date).

place select above in subquery , find avg of response_date - msg_date

update used incorrect table m2.* replaced m1.* , results there

select     avg(unix_timestamp(response_date) - unix_timestamp(msg_date)),     avg(response_date - msg_date) (select     m1.*,     min(m2.msg_date) response_date      edu_messages m1 join     edu_messages m2 on m1.msg_sender = m2.msg_receiver , m2.msg_sender = m1.msg_receiver , m2.msg_date > m1.msg_date  group     m1.msg_sender,     m1.msg_receiver,     m1.msg_date) table1 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -