SELECT prod_province,prod_cnode,prod_balance,rank FROM
(
SELECT b.prod_province,b.prod_cnode,b.prod_balance,@rownum:=@rownum+1 ,
IF(@pdept=b.prod_province,@rank:=@rank+1,@rank:=1) AS rank, @pdept:=b.prod_province
FROM (
SELECT prod_province,prod_cnode,SUM(prod_balance) prod_balance
FROM t_prod_info
GROUP BY prod_province,prod_cnode
ORDER BY prod_province,prod_balance DESC
) b ,(SELECT @rownum :=0 , @pdept := '' ,@rank:=0) c
) result
HAVING rank <4 ;
相关文章
- MYSQL-实现ORACLE- row_number() over(partition by ) 分组排序功能
- Oracle 分析函数row_number() over (partition by order by ) 的 Mysql的替代方法
- mysql 实现 row_number() over(pattition by a order by b )
- Mysql实现row_number和lag()over的功能,不使用变量,求助~
- MySQL 实现Oracle或者PostgreSQL的row_number over 这样的排名语法
- MYSQL-实现row_number() over(partition by ) 分组排序功能
- MYSQL-实现ORACLE- row_number() over(partition by ) 分组排序功能.
- MySQL实现ORALCE的row_number()over(partition by xx)功能