Jump to content

Recommended Posts

Hi,

 

I am having problems with the following query:

 

SELECT status_lead.lead_id, status_lead.status_id, MAX(status_lead.status_version), lead.Date_Logged
FROM status_lead
JOIN lead ON status_lead.lead_ID = lead.lead_ID
WHERE status_lead.status_id =3
AND
lead.Date_Logged BETWEEN DATE_SUB( CURDATE( ) , INTERVAL 2 week ) 
AND DATE_SUB( CURDATE( ) , INTERVAL 1 week ) 
GROUP BY status_lead.lead_id

 

The query works but it doesn't seem to apply the "status_lead.status_id =3" part of the statement. The output always seem to show the correct max value for a unique lead however status_id = 1 and not 3 in most cases.

 

I am querying to find the max value of status_version whereby status_id=3, I hope this makes sense. I am pretty sure I am missing some brackets or something somewhere.

 

Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/143619-max-function-subquery/
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.