时间:2021-07-01 10:21:17 帮助过:4人阅读
while(iStartTime < iEndTime) do
-- 每次加一个小时
set vNextTime = date_add(iStartTime,interval 3600 second);
-- 单引号是特殊字符,要表示单引号,使用 ‘‘ 进行转义
set vSql = concat(vSql,‘union select 100, avg(`value`) from t1 where time between ‘‘‘,iStartTime,‘‘‘ and ‘‘‘, vNextTime,‘‘‘ ‘);
set iStartTime = vNextTime;
end while;
set vSql = substring(vSql,7);
-- 看看拼接的字符串是否正确
-- select vSql;
set @vSql = vSql;
prepare stmt from @vSql;
execute stmt;
deallocate prepare stmt;
END
;;
DELIMITER ;
mysql 求时间段平均值
标签: