title: SQLLite time entry and time exit from eventime
body: <p>I have two tables, <code>DATA</code> and <code>EVENTS</code>, with the following data:</p>
  
  <pre><code>EVENTS
  EventIndex  ObjID   LocID   EventData   EventTime       EventType
  83707365    3519434 10376   0           2013-05-19 11:32:11 137
  83707849    3519434 10374   0           2013-05-19 11:35:18 137 
  83714233    888799  10376   0           2013-05-19 12:24:45 137 
  83715200    888799  10184   0           2013-05-19 12:32:18 137
  
  DATA
  EventIndex  TagName TagValue    
  83714233    ObjName Peter
  83714233    LocName H118
  83715200    ObjName Peter
  83715200    LocName H116
  83707365    ObjName John
  83707365    LocName H118
  83707849    ObjName John
  83707849    LocName H116
  </code></pre>
  
  <p>Where do I start with a SQL SQLLite query?</p>
  
  <p>I want to get the results:</p>
  
  <pre><code>Name   Location  Entry      Exit        Total
  Peter  H118      12:24:45   12:32:18    00:07:33
  John   H118      11:32:11   11:35:18    00:03:07
  </code></pre>
  
  <p>Hi meewoK, can give the following case:</p>
  
  <p>Name     Location    Entry  Exit            Total<br>
  Peter    H118        12:24:45   12:32:18    00:07:33<br>
  John     H118        11:32:11   11:35:18    00:03:07<br>
  John     H118        11:44:52   11:45:27    00:00:35<br>
  John     H118        12:31:15   12:32:46    00:01:31  </p>
  
  <p>and I'm trying to modify your query and I can not find the solution. Thanks</p>
  
  <p>This code works in SQL SERVER:</p>
  
  <p>SELECT E.EventIndex,  N.tagvalue AS Name, L.tagvalue AS Location, E.eventtime AS Entry, NEV.[Exit]<br>
  FROM<br>
      [EVENTS] E<br>
      INNER JOIN [DATA] N ON E.EventIndex = N.eventindex AND N.tagname = 'ObjName'<br>
      INNER JOIN [DATA] L ON E.EventIndex = L.eventindex AND L.tagname = 'LocName'<br>
      OUTER APPLY (<br>
          SELECT TOP (1) NE.eventtime AS [Exit]<br>
          FROM<br>
              [EVENTS] NE<br>
              INNER JOIN [DATA] NL ON NE.EventIndex = NL.eventindex AND   NL.tagname = 'ObjName'<br>
          WHERE<br>
              NE.EventIndex > E.EventIndex<br>
              AND NL.tagvalue = N.tagvalue<br>
          ORDER BY<br>
              NE.EventIndex  </p>
  
  <pre><code>) NEV  
  </code></pre>
  
  <p>WHERE L.tagvalue = 'H118'  </p>
  
  <p>Someone could help me to pass it to SQLite?
  Thanks</p>