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 6548319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:56:13+00:00 2026-05-25T11:56:13+00:00

I have a SQL table where I need to work out the average time

  • 0

I have a SQL table where I need to work out the average time after each transactions:

The data looks like:

Tran1 07/09/2011 09:09:07  - CUSTOMER1 
Tran2 07/09/2011 09:30:46  - CUSTOMER1 
Tran3 07/09/2011 11:27:01  - CUSTOMER2 
Tran4 07/09/2011 11:29:22  - CUSTOMER2 
Tran5 07/09/2011 13:23:48  - CUSTOMER1 
Tran6 08/09/2011 14:21:29  - CUSTOMER3 
Tran7 08/09/2011 14:25:23  - CUSTOMER3 
Tran8 10/09/2011 13:28:57  - CUSTOMER1 
Tran9 10/09/2011 13:30:21  - CUSTOMER1 
Tran10 10/09/2011 13:49:13 - CUSTOMER4

The table is Transaction Table and there are three columns:-

ID = UniqueID, TimeStamp = DataTime, CustomerId = UniqueID

So if I pass in a parameter DateTime.. let say ’10/09/2011′
The result Im trying to achieve is..

Date:10/9/2011 AverageQueueTime:3mins2secs – for exmaple

  • 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-25T11:56:13+00:00Added an answer on May 25, 2026 at 11:56 am

    Assuming your table is named “MyTable” (Is it really named Transaction!?) and that you want the difference in minutes:

    SELECT  CustomerID ,
            SUM(timeSinceLastTransaction) / COUNT(*)
    FROM    ( SELECT    * ,
                        DATEDIFF(MINUTE,
                                 ( SELECT TOP 1
                                            t2.DataTime
                                   FROM     MyTable t2
                                   WHERE    t2.DataTime < t1.DataTime
                                            AND t2.CustomerId = t1.CustomerId
                                   ORDER BY t2.DataTime DESC
                                 ),
                                 t1.DataTime
                                 ) AS timeSinceLastTransaction
              FROM      MyTable t1
            ) AS IndividualTimes
    

    This is a correlated subquery.

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

Sidebar

Related Questions

I have a partitioned table in SQL Enterprise 2005. I need to query the
I have a SQL table with news stories and Unix timestamps. I'd like to
I have a SQL table like so: Update: I'm changing the example table as
I have a sql table which have the following data, Id City Country ---
I have a SQL table where in each row I store the country and
So I have this SQL table that I need to update. Now we use
I'm trying to work out an SQL statement for MySQL. I have a series
I have a sql table called predictions with data as below Week Player Points
I have a sql table : date (Y-m-d) / time (00:00:00) / power (INT)
We have built an internal tool that generates the whole data access, each table

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.