我想为两个日期(@sdate,@edate)之间的每个日期提取一个计数,但它只给我最后一天的计数,而不是所有天的计数。
如何输出所有结果?这是我的存储过程。
DELIMITER $$
USE `cmd_storeinfo`$$
DROP PROCEDURE IF EXISTS `test2`$$
CREATE DEFINER=`USER`@`%` PROCEDURE `test2`()
BEGIN
SET @sdate = (DATE_SUB(CURDATE(), INTERVAL 6 MONTH));
SET @edate = (CURDATE());
SET @x='';
SET @Y='';
WHILE @sdate <= @edate DO
SELECT COUNT(*) INTO @y
FROM cmd_storeinfo.strinfo
WHERE LiveDate <= @sdate AND DeinstallDate >= @sdate OR DeinstallDate IS
NULL AND LiveDate IS NOT NULL
AND CHAIN != 1 && CHAIN != 2 && CHAIN != 999
GROUP BY @sdate
SET @x = @sdate;
SET @sdate = (DATE_ADD(@sdate, INTERVAL 1 DAY));
END WHILE;
SELECT @x,@y;
END$$
DELIMITER ;
谢谢你的帮助。丹尼尔