使用procedure,注意报表是否支持特定关键字(积木报表不支持注入关键字)
drop procedure if exists show_battery_info; delimiter && CREATE PROCEDURE show_battery_info() BEGIN DECLARE `@done` INT DEFAULT 0; DECLARE `@fieldName` VARCHAR(255); DECLARE SysTable CURSOR FOR SELECT DISTINCT kind FROM jupiter.battery_info; DECLARE CONTINUE HANDLER FOR NOT FOUND SET `@done` = 1; OPEN SysTable; read_loop:loop FETCH NEXT FROM SysTable INTO `@fieldName`; IF `@done` =1 THEN LEAVE read_loop; END IF; select * from (select `@fieldName` as type, case when capacity is null then 0 else capacity+0 end as value, DATE_FORMAT(reg_date,'%Y-%m-%d %H:%i:%s') as date from jupiter.battery_info where `@fieldName`=kind order by date desc limit 50)t order by date; SET `@done` = 0; end loop read_loop; CLOSE SysTable; END&& delimiter ; call show_battery_info();
标签:info,遍历,battery,字段,done,mysql,date,fieldName,loop From: https://www.cnblogs.com/anenyang/p/17213893.html