Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE `users` (
- `auth` varchar(32) NOT NULL,
- `name` varchar(32) DEFAULT NULL,
- `country` varchar(128) DEFAULT NULL,
- `ip` varchar(64) DEFAULT NULL,
- `lastlogin` int(11) NOT NULL DEFAULT '-1',
- `points` float NOT NULL DEFAULT '0',
- PRIMARY KEY (`auth`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
- CREATE TABLE `playertimes` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `auth` varchar(32) DEFAULT NULL,
- `map` varchar(192) DEFAULT NULL,
- `time` float DEFAULT NULL,
- `jumps` int(11) DEFAULT NULL,
- `style` int(11) DEFAULT NULL,
- `date` varchar(32) DEFAULT NULL,
- `strafes` int(11) DEFAULT NULL,
- `sync` float DEFAULT NULL,
- `points` float NOT NULL DEFAULT '0',
- `track` int(11) NOT NULL DEFAULT '0',
- PRIMARY KEY (`id`)
- ) ENGINE=InnoDB AUTO_INCREMENT=28399 DEFAULT CHARSET=utf8mb4
- DROP PROCEDURE IF EXISTS UpdateAllPoints;
- DELIMITER ;;
- CREATE PROCEDURE UpdateAllPoints()
- BEGIN
- DECLARE authid VARCHAR(32);
- DECLARE done INT DEFAULT 0;
- DECLARE cur CURSOR FOR (SELECT auth FROM playertimes WHERE points > 0.0 GROUP BY auth);
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
- OPEN cur;
- ranks: LOOP
- FETCH cur INTO authid;
- IF done THEN
- LEAVE ranks;
- END IF;
- UPDATE users u JOIN (SELECT SUM((points * (@f := 0.975 * @f) / 0.975)) total FROM playertimes t
- CROSS JOIN (SELECT @f := 1.0) params WHERE points > 0.0 AND auth = authid ORDER BY points DESC) temp
- SET u.points = temp.total WHERE auth = authid;
- END LOOP;
- CLOSE cur;
- END;;
- DELIMITER ;
Add Comment
Please, Sign In to add comment