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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:42:46+00:00 2026-06-17T12:42:46+00:00

I have a SQLite Database with a table called events, it has the following

  • 0

I have a SQLite Database with a table called “events”, it has the following structure:

rowid       ID                  startTimestamp   endTimestamp
1           00:50:c2:63:10:1a   1000             1010
2           00:50:c2:63:10:1a   1100             1030
3           00:50:c2:63:10:1a   1090             1110   
4           00:50:c2:63:10:1a   1210             1310
.
.
.

It’s no problem to calculate the average time between startTimestamp and endTimestamp:

SELECT ID, avg(endTimestamp - startTimestamp) AS duration FROM events WHERE senderID ="00:50:c2:63:10:1a"

But now i want to have the average differences between the endTime and the startTime between one row and the following row, that means for my example:

1100-1010 = 90

1090-1030 = 60

1210-1110 = 100


Sum of differences = 90 + 60 + 100 = 250

Average Difference = 250 / 3 = 83,33

Is there a way to do this with an SQL Query? Or should is it necessary to write a piece of code in PHP?

  • 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-06-17T12:42:47+00:00Added an answer on June 17, 2026 at 12:42 pm
    SELECT
        id,
        ( MAX(endtimestamp) - MIN(startTimestamp)
        - SUM(endtimestamp-startTimestamp)
        ) / (COUNT(*)-1) AS averageDifference
    FROM
        events
    GROUP BY
        id ;
    

    Tested at SQL-Fiddle: test-1 (thanks to @bonCodigo for that)


    Since the MIN(endtimestamp) may not be the one with lowest rowid, the above query needs a correction:

    SELECT
        id,
        ( ( SELECT endtimestamp FROM events AS ee 
            WHERE ee.id = e.id ORDER BY rowid ASC LIMIT 1 )
        - ( SELECT startTimestamp FROM events AS ee
            WHERE ee.id = e.id ORDER BY rowid DESC LIMIT 1 )
        - SUM(endtimestamp-startTimestamp)
        ) / (COUNT(*)-1) AS averageDifference
    FROM
        events AS e
    GROUP BY
        id ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi all i have the following table called student in SQLite database. this is
i have a table in sqlite database like following. id status ============= x 0
I have a table in SQLite database of Android which has a column RANK
I created a SQLite database via SQLiteManager. I have a table called Envelopes, and
I am creating a SQLite database for my iPhone projects. I have table called
I have a table called catory in my sqlite database that contains some pre
I have a local sqlite server. The SQL database only contains a table called
I have a DataTable which I want to save to a SQLite Database Table.
In this example we have 3 related tables on a SQLite database: CREATE TABLE
I have a table in a SQLite database with multiple key fields (lang and

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.