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
https://forums.phpfreaks.com/topic/111-trouble-with-having-clause/
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
https://forums.phpfreaks.com/topic/111-trouble-with-having-clause/#findComment-336
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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