I have a table called "mytable". The columns are
Time_Stamp (datetime) PK
Time_stamp_ms (int) PK
data1 (int)
data2 (int)
data3 (int)
data4 (int)
data5 (int)
data6 (int)
cycle (int)
name (varstring)
I want to order by Time_Stamp and Time_stamp_ms and then each time cycle reaches 1, I want to get the Time_Stamp and Time_Stamp_ms from the previous row. Cycle is 1,2,3,4......n Means it will always increment by 1.
This table will problably have millions and millions of rows.
Also no PHP.
There is a sample of my table:
Time_Stamp Time_Stamp_ms d1 d2 d3 d4 d5 d6 cycle name
2014-04-24 09:09:37 765 5555 4444 3333 2222 1111 123 1 name
2014-04-24 09:09:37 845 5555 4444 3333 2222 1111 123 2 name
2014-04-24 09:09:37 925 5555 4444 3333 2222 1111 123 3 name
2014-04-24 09:09:38 5 5555 4444 3333 2222 1111 123 4 name
2014-04-24 09:09:38 85 5555 4444 3333 2222 1111 123 5 name
2014-04-24 09:09:38 165 5555 4444 3333 2222 1111 123 6 name
2014-04-24 09:09:38 245 5555 4444 3333 2222 1111 123 7 name
2014-04-24 09:09:38 325 5555 4444 3333 2222 1111 123 8 name
2014-04-24 09:09:38 405 5555 4444 3333 2222 1111 123 9 name
2014-04-24 09:09:38 485 5555 4444 3333 2222 1111 123 10 name
2014-04-24 09:09:38 565 5555 4444 3333 2222 1111 123 11 name
2014-04-24 09:09:38 645 5555 4444 3333 2222 1111 123 12 name
2014-04-24 09:09:38 725 5555 4444 3333 2222 1111 123 13 name
2014-04-24 09:09:38 805 5555 4444 3333 2222 1111 123 1 name
2014-04-24 09:09:38 885 5555 4444 3333 2222 1111 123 2 name
2014-04-24 09:09:38 965 5555 4444 3333 2222 1111 123 3 name
2014-04-24 09:09:39 45 5555 4444 3333 2222 1111 123 4 name
2014-04-24 09:09:39 125 5555 4444 3333 2222 1111 123 5 name
2014-04-24 09:09:39 205 5555 4444 3333 2222 1111 123 6 name
2014-04-24 09:09:39 285 5555 4444 3333 2222 1111 123 1 name
2014-04-24 09:09:39 365 5555 4444 3333 2222 1111 123 2 name
2014-04-24 09:09:39 445 5555 4444 3333 2222 1111 123 3 name
2014-04-24 09:09:39 525 5555 4444 3333 2222 1111 123 4 name
2014-04-24 09:09:39 605 5555 4444 3333 2222 1111 123 5 name
2014-04-24 09:09:39 685 5555 4444 3333 2222 1111 123 6 name
2014-04-24 09:09:39 765 5555 4444 3333 2222 1111 123 1 name
2014-04-24 09:09:39 845 5555 4444 3333 2222 1111 123 2 name
2014-04-24 09:09:39 925 5555 4444 3333 2222 1111 123 3 name
Should return me:
Time_Stamp Time_Stamp_ms d1 d2 d3 d4 d5 d6 cycle name
2014-04-24 09:09:38 725 5555 4444 3333 2222 1111 123 13 name
2014-04-24 09:09:39 205 5555 4444 3333 2222 1111 123 6 name
2014-04-24 09:09:39 685 5555 4444 3333 2222 1111 123 6 name
How do I do this?