Below tables :I am trying to calculate
openLeadsCount having status 1
I tried but getting wrong results
SELECT COUNT(lead.id) FROM lead JOIN lead_status ls WHERE ls.lead_id=lead.id
AND ls.id=(SELECT MAX(id) FROM lead_status lst WHERE lst.status=1 )
Lead table:
id created_on
1 2014-1-13
2 2014-1-18
lead_status table
id lead_id created_on lead_status
1 1 2014-01-13:05:00 1
2 1 2014-01-14:06:00 2
3 1 2014-01-14:06:00 1
4 2 2014-01-14:06:00 1