Guest User

Untitled

a guest
Oct 24th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. CREATE TABLE `users` (
  2. `auth` varchar(32) NOT NULL,
  3. `name` varchar(32) DEFAULT NULL,
  4. `country` varchar(128) DEFAULT NULL,
  5. `ip` varchar(64) DEFAULT NULL,
  6. `lastlogin` int(11) NOT NULL DEFAULT '-1',
  7. `points` float NOT NULL DEFAULT '0',
  8. PRIMARY KEY (`auth`)
  9. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
  10.  
  11. CREATE TABLE `playertimes` (
  12. `id` int(11) NOT NULL AUTO_INCREMENT,
  13. `auth` varchar(32) DEFAULT NULL,
  14. `map` varchar(192) DEFAULT NULL,
  15. `time` float DEFAULT NULL,
  16. `jumps` int(11) DEFAULT NULL,
  17. `style` int(11) DEFAULT NULL,
  18. `date` varchar(32) DEFAULT NULL,
  19. `strafes` int(11) DEFAULT NULL,
  20. `sync` float DEFAULT NULL,
  21. `points` float NOT NULL DEFAULT '0',
  22. `track` int(11) NOT NULL DEFAULT '0',
  23. PRIMARY KEY (`id`)
  24. ) ENGINE=InnoDB AUTO_INCREMENT=28399 DEFAULT CHARSET=utf8mb4
  25.  
  26. DROP PROCEDURE IF EXISTS UpdateAllPoints;
  27. DELIMITER ;;
  28. CREATE PROCEDURE UpdateAllPoints()
  29. BEGIN
  30. DECLARE authid VARCHAR(32);
  31. DECLARE done INT DEFAULT 0;
  32. DECLARE cur CURSOR FOR (SELECT auth FROM playertimes WHERE points > 0.0 GROUP BY auth);
  33. DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
  34. OPEN cur;
  35. ranks: LOOP
  36. FETCH cur INTO authid;
  37. IF done THEN
  38. LEAVE ranks;
  39. END IF;
  40. UPDATE users u JOIN (SELECT SUM((points * (@f := 0.975 * @f) / 0.975)) total FROM playertimes t
  41. CROSS JOIN (SELECT @f := 1.0) params WHERE points > 0.0 AND auth = authid ORDER BY points DESC) temp
  42. SET u.points = temp.total WHERE auth = authid;
  43. END LOOP;
  44. CLOSE cur;
  45. END;;
  46. DELIMITER ;
Add Comment
Please, Sign In to add comment