mysql存储过程中的查询语句有时候执行不成功,我的数据库里有800万条记录,大部分时候都能执行成功 20
存储过程代码:delimiter//CREATEPROCEDUREqueryAddNumOfDay(inpMonthINT)BEGINSET@startDate=CONC...
存储过程代码:
delimiter //
CREATE PROCEDURE queryAddNumOfDay(in pMonth INT)
BEGIN
SET @startDate = CONCAT(SUBSTR(pMonth, 1, 4), "-", SUBSTR(pMonth, 5, 2), "-", "01");
SET @endDate = LAST_DAY(@startDate);
DELETE FROM ta_tj_add_day WHERE days >= @startDate AND days <= @endDate;
SET @preNum = 0;
SELECT @preNum := COUNT(DISTINCT deviceid) FROM ta_app_download_log WHERE type = '7' AND DATE(download_time) < @startDate;
while @startDate <= @endDate DO
SET @curNum = 0;
SELECT @curNum := COUNT(DISTINCT deviceid) FROM ta_app_download_log WHERE type = '7' AND DATE(download_time) <= @startDate;
INSERT INTO ta_tj_add_day(add_num, days) VALUES (@curNum - @preNum, @startDate);
SET @startDate = DATE_ADD(@startDate, INTERVAL 1 DAY);
set @preNum = @curNum;
END WHILE;
END;
//
delimiter ;
其中的查询语句:
SELECT @curNum := COUNT(DISTINCT deviceid) FROM ta_app_download_log WHERE type = '7' AND DATE(download_time) <= @startDate;
我感觉这个查询有时候没执行成功、或者没执行导致错误 展开
delimiter //
CREATE PROCEDURE queryAddNumOfDay(in pMonth INT)
BEGIN
SET @startDate = CONCAT(SUBSTR(pMonth, 1, 4), "-", SUBSTR(pMonth, 5, 2), "-", "01");
SET @endDate = LAST_DAY(@startDate);
DELETE FROM ta_tj_add_day WHERE days >= @startDate AND days <= @endDate;
SET @preNum = 0;
SELECT @preNum := COUNT(DISTINCT deviceid) FROM ta_app_download_log WHERE type = '7' AND DATE(download_time) < @startDate;
while @startDate <= @endDate DO
SET @curNum = 0;
SELECT @curNum := COUNT(DISTINCT deviceid) FROM ta_app_download_log WHERE type = '7' AND DATE(download_time) <= @startDate;
INSERT INTO ta_tj_add_day(add_num, days) VALUES (@curNum - @preNum, @startDate);
SET @startDate = DATE_ADD(@startDate, INTERVAL 1 DAY);
set @preNum = @curNum;
END WHILE;
END;
//
delimiter ;
其中的查询语句:
SELECT @curNum := COUNT(DISTINCT deviceid) FROM ta_app_download_log WHERE type = '7' AND DATE(download_time) <= @startDate;
我感觉这个查询有时候没执行成功、或者没执行导致错误 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询