MYSQL 存储过程实现类似ORACLE row_number 和 rank 的简单例子
row_number 实现: DELIMITER $$ USE `zhangzm`$$ DROP PROCEDURE IF EXISTS `row_number`$$ CREATE DEFINER=`root`@`%` PROCEDURE `row_number`() BEGIN DECLARE rn INT DEFAULT 0 ; DECLARE _StuId VARCHAR (5) ; DECLARE _CourseId VARCHAR (3) ; DECLARE _Score FLOAT ; DECLARE last_CourseId VARCHAR (3) ; DECLARE done TINYINT DEFAULT FALSE ; DECLARE cur CURSOR FOR SELECT `StuId`, `CourseId`, `Score` FROM `zhangzm`.`tblScore` ORDER BY `CourseId`, `Score` DESC ; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE ; DROP TABLE IF EXISTS temp_tblScore ; CREATE TEMPORARY TABLE temp_tblScore LIKE `zhangzm`.