P Kishor <[EMAIL PROTECTED]> wrote:
> On 3/14/08, BandIT
> <[EMAIL PROTECTED]> wrote:
>>
>>  I have a table:
>>
>>  CREATE TABLE Log
>>  (
>>   TimeStamp char(14),  -> Format YYYYMMDDHHNNSS
>>   Code char(5),    -> 5 digit status code
>>  )
>>
>>  example:
>>
>>  20080314100030 A0001
>>  20080314101000 A0002
>>  20080314101700 A0000
>>  20080314102000 A0002
>>  20080314102100 A0000
>>
>>  I would like a query to output the the time between the status
>>  codes (sum) to know how long each status has been active. I am not
>>  so very familiar with SQL and SQLite, and I hope I am posting to
>> the correct forum.
>
> SELECT Code, max(TimeStamp) -min(TimeStamp) AS TimePassed
> FROM Log
> GROUP BY Code;

That would give TimePassed of zero for any code that only appears once. 
It will also overcount codes that appeared more than once, but with 
other codes in between (such as A0002).

Igor Tandetnik 



_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to