I want to create an SQL Query for a SQLite3 DB.
In my table I have the following sample data
7/1/2011 8:00 LOGIN
7/1/2011 10:12 LOGOFF
7/1/2011 10:20 LOGIN
7/1/2011 17:15 LOGOFF
7/2/2011 9:00 LOGIN
7/3/2011 10:00 LOGIN
7/3/2011 20:00 LOGOFF
basically I want to only get the first LOGIN entry per date and the last LOGOFF entry for the same date (if available)
So I want the query to produce
7/1/2011 8:00 LOGIN
7/1/2011 17:15 LOGOFF
7/2/2011 9:00 LOGIN
7/3/2011 10:00 LOGIN
7/3/2011 20:00 LOGOFF
Is is also possible to calculate the difference in Time with the desired output table?
IE/ on 7/1/2011 would be 9:15
Supposing your columns are named
Date, Time, Action, this is what you need:Update
For calculating the difference, you might want to “flatten” the rows of a day to a single row:
Some considerations:
Diffwill be nullDiff. Do some research on that for SQLite, every RDBMS has its particularities on that matter.