See if this logic helps you, it will get you close, you may need to refine it
basically it finds out how many years it has been since the person signed up, subtracts 3 from it, then adds that number to the sign up date and gets all records after that new date SELECT * FROM Users u, User_Actions ua WHERE u.id = ua.user_id AND ua.date >= ADDDATE(u.sign_up_date, INTERVAL (YEAR(NOW()) - YEAR(u.sign_up_date)) - 3) YEAR) Justin Giboney On Thu, Jan 28, 2010 at 2:37 AM, Wade Preston Shearer <[email protected]> wrote: > I have a difficult MySQL query to write. Is there anyone that can assist? > > I have a users table. I have another table with things the user does. > > I need to select all the things the user has done within the current three > year window since the date the user's account was created. > > > Example: > > So, if the user's account was created in Feb 2001, they did something in Mar > 2003, something in Nov 2009, and something else in Jan 2010, the query would > return 2 records, because they did… > > . one thing in the first three years > . nothing in the second three years > . and two things in the third (current) three year period > > > …and we only want the things that were done within the current three year > period. > > > Is that possible in a single query? > > _______________________________________________ > > UPHPU mailing list > [email protected] > http://uphpu.org/mailman/listinfo/uphpu > IRC: #uphpu on irc.freenode.net > _______________________________________________ UPHPU mailing list [email protected] http://uphpu.org/mailman/listinfo/uphpu IRC: #uphpu on irc.freenode.net
