I want to achieve this
ID | NAME | CODE | TIME | Start | Stop
--------|------|------|-----------------------|---------------------|------------
4B37B930| EV | FI | 2017-10-20 08:30:00 | 2017-10-20 08:30:00 | 2017-10-20 08:34:00
3333E8C4| HK | FI | 2017-10-20 12:33:00 | 2017-10-20 12:33:00 | 2017-10-20 12:36:00
EF84D06D| HK | SE | 2017-10-20 12:37:00 | 2017-10-20 12:37:00 | 2017-10-20 12:39:00
from these rows in the same table
ID | NAME | CODE | TIME | Start | Stop
--------|------|------|-----------------------|-----------|------------
4B37B930| EV | FI | 2017-10-20 08:30:00 | |
7AA6E032| EV | FI | 2017-10-20 08:33:00 | |
B59D4931| EV | FI | 2017-10-20 08:34:00 | |
3333E8C4| HK | FI | 2017-10-20 12:33:00 | |
1C4890A1| HK | FI | 2017-10-20 12:34:00 | |
AA246243| HK | FI | 2017-10-20 12:35:00 | |
A99DFF3C| HK | FI | 2017-10-20 12:36:00 | |
EF84D06D| HK | SE | 2017-10-20 12:37:00 | |
1D8C4963| HK | SE | 2017-10-20 12:38:00 | |
0358656B| HK | SE | 2017-10-20 12:39:00 | |
That is to delete rows if they are within 5 min and have same NAME and CODE value in the table. Please notice that it is ok for upto 5 consecutive rows to be missing, in this case rows with TIME value 08:31, 08:32 are missing but still I want the first three rows from table 2 to be replaced with one row as shown in table 1 row 1, and similarly, rows 4-7 from table 2 to be replaced with row 2 in table 1 and so on.
Here is a link so SQL fiddle http://sqlfiddle.com/#!9/44af04/1/0