this morning i involved by this query . i wasted my 2 days . but not got good solution . I have a mysql query
SELECT l.date_entered, n.date_entered, n.date_modified, n.name, n.parent_id
FROM `notes` AS n, leads AS l
WHERE n.parent_type = "Leads" && MONTH( l.date_entered ) =1 && YEAR( l.date_entered ) =2013 &&
n.parent_id = l.id
ORDER BY n.date_modified ASC
This is giving me this output:-
date_entered date_entered date_modified name parent_id
2013-01-07 2013-01-07 2013-01-07 20:17:44 rahul 100
2013-01-07 2013-01-07 2013-01-07 22:27:38 rawat 101
2013-01-03 2013-01-07 2013-01-07 23:29:02 rohit 102
2013-01-03 2013-01-07 2013-01-07 23:33:55 mamta 100
2013-01-04 2013-01-08 2013-01-08 06:16:11 kiran 101
2013-01-07 2013-01-08 2013-01-08 07:10:10 ajay 100
Now, I am trying to get the date-modified difference by matching on parent_id e.g.
- Starting with 100, search returns another 100 in 4th row. This date-modified the same day, so result = 0
- Next search is for 101 which is found in 5th row. This date-modified is 1 day after the previous 101, so result = 1
- Next search is for 102, which is not found, so skip it
- Next search is for 100, but this has already been found, so skip it
- Next search is for 101, but this has already been found, so skip it
- Next search is for 100, but this has already been found, so skip it
my output will be such as:-
date_entered date_entered date_modified name parent_id datediff
2013-01-07 2013-01-07 2013-01-07 20:17:44 rahul 100 0
2013-01-07 2013-01-07 2013-01-07 22:27:38 rawat 101 1
2013-01-03 2013-01-07 2013-01-07 23:29:02 rohit 102 not found
2013-01-03 2013-01-07 2013-01-07 23:33:55 mamta 100 skip due to previous match
2013-01-04 2013-01-08 2013-01-08 06:16:11 kiran 101 skip due to previous match
2013-01-07 2013-01-08 2013-01-08 07:10:10 ajay 100 skip due to previous match
Try this :
This works. Check SQL Fiddle