CREATE DEFINER=`admin`@`%` PROCEDURE `test_1`()
BEGIN
DECLARE v_id INT;
DECLARE v_Max INT;
DECLARE v_Min INT;
DECLARE v_flag INT;
DECLARE v_count INT;
SELECT COUNT(id) INTO v_count FROM test123;
SELECT MAX(COUNT),MIN(COUNT) INTO v_Max,v_Min FROM test123;
SET v_flag=1;
WHILE v_Max >= v_Min DO
SELECT id INTO v_id FROM test123 WHERE COUNT=v_Max;
IF FOUND_ROWS() >=1 THEN
UPDATE test123 SET rank=v_flag WHERE id=v_id;
SET v_flag=v_flag+1;
END IF;
SET v_Max = v_Max - 1;
SELECT v_id;
END WHILE;
END$$