wwwwb看着吧
CREATE DEFINER=`root`@`localhost` PROCEDURE `diyi`(
IN days int,
IN day1 int,
INOUT game VARCHAR(50) character set gb2312,
IN serverorder int,
IN serverid int,
IN game1 varchar(20) character set gb2312
)
BEGIN
DECLARE countj INT; -- 临时存储重复UID总数
DECLARE i INT; -- 临时循环变量存储
DECLARE days INT;
DECLARE game varchar(50) character set gbk;
DECLARE game1 varchar(50) character set gbk;
DECLARE serverorder INT;
DECLARE serverid INT;
DECLARE day1 INT;
SET i=1;
SELECT count(DISTINCT(days)) INTO countj FROM `count_serverinfo` WHERE gameid = '",game,"';
SELECT days INTO days FROM `count_serverinfo` WHERE gameid = '",game,"' GROUP BY days asc ;
WHILE i <= countj DO
BEGIN
SELECT game,serverorder,serverid,MAX(IF(days='",days,"',amountcount,0.00)) AS '",days,"' INTO game1,serverorder,serverid,day1 FROM count_serverinfo GROUP BY serverid ORDER BY serverorder DESC;
END;
SET i = i +1;
END WHILE;
END
------解决方案--------------------
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `diyi`(
IN days INT,
IN day1 INT,
INOUT game VARCHAR(50) CHARACTER SET gb2312,
IN serverorder INT,
IN serverid INT,
IN game1 VARCHAR(20) CHARACTER SET gb2312
)
BEGIN
DECLARE countj INT; -- 临时存储重复UID总数
DECLARE i INT; -- 临时循环变量存储
DECLARE days INT;
DECLARE game VARCHAR(50) CHARACTER SET gbk;
DECLARE game1 VARCHAR(50) CHARACTER SET gbk;
DECLARE serverorder INT;
DECLARE serverid INT;
DECLARE day1 INT;
SET i=1;
SELECT COUNT(DISTINCT(days)) INTO countj FROM `count_serverinfo` WHERE gameid = '",game,"';
SELECT days INTO days FROM `count_serverinfo` WHERE gameid = '",game,"' GROUP BY days ASC ;
WHILE i <= countj DO
BEGIN
SELECT game,serverorder,serverid,MAX(IF(days='",days,"',amountcount,0.00)) AS '",days,"' INTO game1,serverorder,serverid,day1 FROM count_serverinfo GROUP BY serverid ORDER BY serverorder DESC;
END;
SET i = i +1;
END WHILE;
END$$
DELIMITER ;
------解决方案--------------------
还有临时表,退出后自动删除