I have used the following postgresql query to find the maximum difference between timestamp events for each user:
select sq.user_id, max(sq.diffs) inactiv