I have this records in MySQL below
RecID | Description | Date | Hits | IsPublished
1; "Test"; 04/10/2012; 45; True
2; "Test 1"; 04/10/2012; 37; True
3; "Test 2"; 05/10/2012; 12; True
4; "Test 3"; 05/10/2012; 13; True
5; "Test 4"; 07/10/2012; 14; True
6; "Test 5"; 07/10/2012; 25; True
7; "Test 4"; 08/10/2012; 23; True
8; "Test 5"; 08/10/2012; 35; True
9; "Test 9"; 12/10/2012; 7; True
Would like to achieve the following
9; "Test 9"; 12/10/2012; 7; True
8; "Test 5"; 08/10/2012; 35; True
4; "Test 3"; 05/10/2012; 13; True
Basically, the first rule is to group the date which is 08/10/2012, 07/10/2012 and 05/10/2012 and 04/10/2012. Use this 08/10/2012 as a starting point. Then remove any dates that is close to each other (min 1 day).
BTW … this is an Australian date (DD/MM/YYYY). Therefore, the result is 08/10/2012, 05/10/2012. Out of these 2 “valid” days and then pick the record that has more hits on that day. Then set the others as IsPublished = false.
Any ideas to do this in MySQL?
First find the dates that have no other rows with a day larger by 1:
Then find the max hits for these dates:
Finally, update all rows that don’t match these dates and maxHits: