Jump to content

trouble with having clause...


dotnet

Recommended Posts

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.