Selecting info from users who have been inactive for at least a week
Assuming the date you are referring to is t_week.created_at, not i.created_at:

select * from (
    select DISTINCT ON (u.id) u.id, t_week.created_at, ... 
        FROM users u JOIN task t_week on u.id = t_week.user_id JOIN...
        ORDER by u.id, t_week.created_at desc
) foo 
WHERE t_week.created_at &lt; %s
ORDER BY u.id, i.created_at


You have to use the sub-select because DISTINCT ON doesn't support a HAVING clause, so you wrap it in a sub-select and use a WHERE clause on the outside.

This would not find people have never done a task all.  To do that you would need to do a left join to task table, then 

WHERE t_week.created_at &lt; %s or t_week.created_at is null