I am having problems understanding how best to tackle this query.
I have a table called user_files. A user can have many files. I want to get a list of users who have not modified any of their files within the last year. If a user has modified at least one of their files within the last year, then that user should be excluded.
Table: user_files
file_id | user_id | date_modified
----------------------------------
1 100 2010-10-01
2 100 2010-11-13
3 100 2011-01-01
4 101 2010-10-01
5 101 2010-06-13
6 101 2011-04-12
7 101 2012-04-01
The expected result would only list user_id 100.
Here is some bad sql I have been playing with. The idea is that I find all users who recently modified their files and then find users who are not included in that list.
select user_id from users where user_id not in
(
select user_id from
(
select user_id, story_id, max(date_modified) from user_files
where DATE_FORMAT(date_modified, '%Y-%m-%d') >= DATE_SUB(curdate(), INTERVAL 1 YEAR)
group by user_id
)x
)
Thanks