DROP TEMPORARY TABLE IF EXISTS tData;
CREATE TEMPORARY TABLE tData
	SELECT 1 `group`, 1 `ival`, 10 `num`
	UNION SELECT 1, 3, -2
	UNION SELECT 1, 2, 1
	UNION SELECT 1, 3, -1
	UNION SELECT 1, 2, -5
	UNION SELECT 2, '1', 20
	UNION SELECT 2, '3', -5
	UNION SELECT 2, '2', 1
	UNION SELECT 2, '3', 10
	UNION SELECT 2, '2', -6
	UNION SELECT 3, 2, 8
	UNION SELECT 3, 3, 10
	UNION SELECT 4, 2, 10
	UNION SELECT 4, 3, -24
	UNION SELECT 5, NULL, 0
	UNION SELECT 5, NULL, -4;

DROP TEMPORARY TABLE IF EXISTS tExpect;
CREATE TEMPORARY TABLE tExpect
	SELECT 1 `group`, 3 expect
	UNION SELECT 2, 15
	UNION SELECT 3, 0
	UNION SELECT 4, -14
	UNION SELECT 5, -4;

SELECT e.`group`, r.result, e.expect, r.result <=> e.expect isRight
	FROM tExpect e
		LEFT JOIN (
			SELECT `group`, minacum(`ival`, `num`, 1) result
				FROM tData GROUP BY `group`
		) r ON r.`group` = e.`group`;

DROP TEMPORARY TABLE tData, tExpect;