Solved

Subtracting rows as opposed to columns

Posted on 2013-12-01
1
175 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
1 Comment
 
LVL 24

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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