如何将此Mysql语句转换为存储过程

如何将此Mysql语句转换为存储过程,mysql,stored-procedures,Mysql,Stored Procedures,有人能告诉我如何为这个mysql语句创建存储过程吗: SELECT city, country, population FROM (SELECT city, country, population, @country_rank := IF(@current_country = country, @country_rank + 1, 1) AS country_rank, @current_country := country FROM cities

有人能告诉我如何为这个mysql语句创建存储过程吗:

SELECT city, country, population
FROM
  (SELECT
     city, country, population, 
     @country_rank := IF(@current_country = country, @country_rank + 1, 1) AS country_rank,
     @current_country := country 
   FROM cities
   ORDER BY country, population DESC
  ) ranked
WHERE country_rank <= 2;

至少要学习如何使用存储过程

DELIMITER $$

DROP PROCEDURE IF EXISTS `db_name`.`stored_procedure_name`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `stored_procedure_name`(out var1 varchar(100))
BEGIN
    SELECT city, country, population
    FROM
      (SELECT
         city, country, population, 
         @country_rank := IF(@current_country = country, @country_rank + 1, 1) AS country_rank,
         @current_country := country 
       FROM cities
       ORDER BY country, population DESC
      ) ranked
    WHERE country_rank <= 2;

END$$

DELIMITER ;

请帮助我们帮助您:您的程序需要做什么?