Solved

Subtracting rows as opposed to columns

Posted on 2013-12-01
1
176 Views
Last Modified: 2013-12-02
I have a table that holds the end time, activity id, record number. What I need to do is subtract record 2's time from record 1' time, record 4's time from record 3's time.

table data
started      activity Id      record Id
11/14/2013 11:06:29 PM      1257      1
11/15/2013 2:09:57 PM      1291      2
11/18/2013 4:26:34 AM      1257      3
11/18/2013 4:48:53 PM      1291      4
11/19/2013 2:54:52 AM      1257      5
11/19/2013 3:42:00 PM      1291      6
11/21/2013 2:24:38 AM      1257      7
11/21/2013 2:08:06 PM      1291      8

I have no idea how to do this, can someone please assist.
0
Comment
Question by:portlight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 25

Accepted Solution

by:
chaau earned 500 total points
ID: 39688703
If the `record id` of the second row is always bigger by one, then this statement will calculate you the time difference (in seconds)
select a.started a_started, 
b.started b_started, 
timestampdiff(second, a.started, b.started) secondsPassed
FROM Table1 a INNER JOIN Table1 b
ON a.`record Id` = b.`record id` - 1

Open in new window

0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question