Selecting info from users who have been inactive for at least a week
0
votes
1
answer
153
views
I need to find the users who have not done a task in at least a week, and pull the relevant information from them. In this case, their id, names, and data1 from another table. This is what I have so far, but it's not working. Something to do with the joins I think?
Can someone help me out? :)
Additional info: the user_identity table is a bit complicated, with multiple rows with the same userid hence the distinct.
SELECT DISTINCT ON (u.id) u.id, u.given_name, u.family_name, i.data1
FROM users u JOIN task t_week on u.id = t_week.user_id
and t_week.created_at > %s JOIN user_identity i on (u.id=i.user_id)
WHERE t_week.created_at IS NULL AND i.content_type='email_address' AND i.owner_id is NULL
GROUP BY u.id, u.given_name, u.family_name, i.data1,i.created_at ORDER BY u.id, i.created_at
Asked by Wboy
(103 rep)
Aug 12, 2016, 04:18 AM
Last activity: Jul 13, 2025, 05:08 PM
Last activity: Jul 13, 2025, 05:08 PM