I have a table which tracks the user actions in a web-site. A simplified version is as follows

```
user_id | action_time             | module_name
--------+-------------------------+------------
1       | 2014-03-02 11:13:08.775 | home
1       | 2014-03-02 11:13:08.345 | user
1       | 2014-03-02 11:13:08.428 | discussions

```

How much time did a user spend on each screen? So take the least `action_time` for a user, get the next one, find the difference.

I think this calls for a recursive query, but not able to get my head around it. One thing - I wouldn't know when to stop. After some "module" the user could have just closed the browser, without bothering to logout. So "closure" is a bit tricky.