Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6834663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:08:20+00:00 2026-05-26T23:08:20+00:00

Is it possible to calculate the average time to reply to a message just

  • 0

Is it possible to calculate the average time to reply to a message just with the following columns:

id | ref | client | admin | date | message
  • id is the unique message number
  • ref is the message reference number, which is not unique (searching for ref, ordering by date will show a conversation)
  • client is ID of client, if it is a client message, else 0 if not a client
  • admin is ID of admin, if it is an admin message, else 0 if not a client
  • date is set up using datetime being the time of the message
  • message being the message sent

Example Data:

1  | 1   | 1      | 0     | 2011-11-07 01:00:00 | ABC
2  | 1   | 1      | 0     | 2011-11-07 01:01:00 | DEF
3  | 1   | 0      | 1     | 2011-11-07 01:05:00 | abc
4  | 2   | 2      | 0     | 2011-11-07 01:10:00 | 123
5  | 3   | 1      | 0     | 2011-11-07 01:11:00 | abc
6  | 2   | 0      | 1     | 2011-11-07 01:20:00 | a
7  | 3   | 0      | 2     | 2011-11-07 02:11:00 | b

Ideally looking for the average time period between a client message and an admin message, though if there are 2 client messages from the same client (ie. admin didn’t reply to first message before client added their 2nd message) with the same ref.

From example, time for (1) = 5 minutes, (2) = 10 minutes, (3) = 60 minutes … average = 25 minutes (1500 seconds – happy to get work with seconds)

I’m not sure how to even begin working on this…. I do hope someone can help :S

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:08:21+00:00Added an answer on May 26, 2026 at 11:08 pm

    Your question is well formulated but leaves room for interpretation. This is one interpretation:

    SELECT avg(TIMESTAMPDIFF(SECOND, c.c_date, a.a_date) AS avg_time_to_response
    FROM   (
        SELECT ref, min(date) AS c_date
        FROM   tbl
        WHERE  client > 0
        GROUP  BY 1
        ) c
    JOIN  (
        SELECT ref, min(date) AS a_date
        FROM   tbl
        WHERE  admin > 0
        GROUP  BY 1
        ) a USING (ref)
    WHERE a.a_date > c.c_date;
    

    Gives you the average time that passes between the first client posting and the first admin posting per thread (message reference number).

    Unanswered messages are ignored. Threads started by Admins would confuse the result with negative durations, so I excluded those. Only the first response time per thread goes into the result. Additional postings on the same thread are ignored here.

    Read the manual here about TIMESTAMPDIFF().
    Thanx to @MrJ and @Vincent for pointing out the mistake with the subtraction of timestamps!

    Concerning GROUP BY 1

    I quote the manual here:

    Columns selected for output can be referred to in ORDER BY and GROUP
    BY clauses using column names, column aliases, or column positions.
    Column positions are integers and begin with 1:

    Emphasis mine. So I group on the first column that is selected (ref in both cases). Just a notational shortcut.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is possible to calculate average of three encrypted integer? No constrain on the method
I was wondering if it's possible to calculate the average of some numbers if
Possible Duplicate: how to calculate the current speed and average speed of user travelling
Possible Duplicate: Calculate years from date Hi, I have a table with a field
Would it be possible to calculate time online from a table of something like
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
I need to calculate Math.exp() from java very frequently, is it possible to get
It is easy to calculate a sum, an average or a maximum accross set
Possible Duplicate: Calculate Bounding box coordinates from a rotated rectangle, Picture inside. I have
Is it possible to calculate the row position in the cartesian product of two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.