dotnet Posted January 31, 2003 Share Posted January 31, 2003 hey everyone, I\'m having trouble using the having clause... here\'s my situation: I have a table of users, and the date they joined... I want data of the users who signed up in the last 7 days before the last user signup... so my sql statement looks something like this: SELECT * from userlist HAVING created_date <= max(created_date) and created_date >= (max(created_date) - (7 * 24 * 60 * 60)) it either returns everything in the table, or nothing... have be head over heels... thanks for your help... Quote Link to comment https://forums.phpfreaks.com/topic/111-trouble-with-having-clause/ Share on other sites More sharing options...
pallevillesen Posted January 31, 2003 Share Posted January 31, 2003 EDIT: Whoups.... the calculation fucks it up... You should convert the created_date to seconds first... Hang on... GOT IT... Use UNIX_TIMESTAMP(date) to convert to seconds.... /EDIT Try: expr BETWEEN min AND max SELECT * from userlist WHERE ( UNIX_TIMESTAMP(created_date) BETWEEN (max(UNIX_TIMESTAMP(created_date)) - (7 * 24 * 60 * 60)) AND max(UNIX_TIMESTAMP(created_date)) ); P. Quote Link to comment https://forums.phpfreaks.com/topic/111-trouble-with-having-clause/#findComment-336 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.