With questions of finding gaps in consecutive records I find it fun to use Cursors to iterate through the records. I don't see them used often here, but I think they are easier to wrap the head around than the sometime intricate self joins, etc.
CREATE PROCEDURE findgaps()
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE idv, datedeltav, itemcodev, prev_itemcodev INT;
DECLARE datev, prev_datev DATE;
DECLARE cur CURSOR FOR SELECT id, date, datedelta, itemcode
FROM sales
ORDER BY itemcode ASC, date ASC;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cur;
read_loop: LOOP
SET prev_datev = datev;
SET prev_itemcodev = itemcodev;
FETCH cur INTO idv, datev, datedeltav, itemcodev;
IF done THEN
LEAVE read_loop;
END IF;
IF NOT itemcodev <=> prev_itemcodev THEN
SET prev_datev = datev;
END IF;
UPDATE sales s
SET s.datedelta = DATEDIFF(datev,prev_datev)
WHERE s.id = idv;
END LOOP;
CLOSE cur;
END;
I haven't tested or debugged this, but this will roughly do it for you.