CREATE TABLE Data (d DATE, i INT);
INSERT INTO Data VALUES ('2017-02-01', 10), ('2017-02-05', 6),
('2017-02-05', 7), ('2017-02-07', 4);
DELIMITER $$
CREATE PROCEDURE all_those_days(IN start DATE, IN stop DATE)
BEGIN
DROP TEMPORARY TABLE IF EXISTS series;
CREATE TEMPORARY TABLE series (d DATE PRIMARY KEY) ENGINE = MEMORY;
WHILE start < stop DO
INSERT INTO series VALUE (start);
SELECT DATE_ADD(start, INTERVAL +1 DAY) INTO start;
END WHILE;
SELECT series.d, COALESCE(SUM(Data.i), 0) AS i
FROM series LEFT JOIN Data ON series.d = Data.d GROUP BY series.d;
END $$
DELIMITER ;
CALL all_those_days('2017-02-01', '2017-02-10');