0

I have a database that time stamps every five minutes, or less if the user stops the database. How can I take the sum of the difference between the time stamps and add them up?

EDIT

I have six different times all five minutes apart and one time the is, lets say, only 2 minutes from the last logged auto time that have been logged by the user:

13:41:33

13:46:33

13:51:33

13:56:33

14:01:33

14:06:33

14:08:27

now I want to take the times and add a mark that says its how many minutes from the last logged time:

13:41:33 = 0 //will be zero cause that is where the user started timing

13:46:33 = 5

13:51:33 = 5

13:56:33 = 5

14:01:33 = 5

14:06:33 = 5

14:08:27 = 2

After that I want my application to take all the fives and the twos and add them up:

0 +

5 +

5 +

5 +

5 +

5 +

2 =

27 minutes

Christian
  • 958
  • 5
  • 23
  • 52

1 Answers1

0

Use a SQL SUM function on that column and it should give you your result. You should probably tag your question with more specific tags (SQLite, SQL, Etc)

Jon Douglas
  • 13,006
  • 4
  • 38
  • 51
  • Could I have an example of the `SUM` function? – Christian Jan 12 '12 at 23:31
  • I forgot to mention that you're going to need to truncate the data. For example 14:08:27 will need to be 08:27 and then you can subtract accordingly. Once you do that to each row, you will then take the SUM – Jon Douglas Jan 13 '12 at 19:55
  • I keep getting an error saying no such column: SUM: , while compiling: SELECT SUM JobTime FROM wwlltdTable my query looks like return ourdb.rawQuery("SELECT SUM "+KEY_TIME+" FROM " + WW_LLTDTABLE , null); KEY_TIME is set as numeric – Christian Jan 13 '12 at 20:30
  • Also I have tried Cursor c = ourdb.rawQuery("SELECT "+KEY_ROWIDLATLON+" SUM"+"("+KEY_FIVEMINUTES+")"+" FROM " + WW_LLTDTABLE , null); return c; and it says that the error is now near `(` – Christian Jan 13 '12 at 20:51
  • So I did get it working I had to have my constructor a double instead of a cursor. Thank you for your time – Christian Jan 13 '12 at 21:18