mysql 实现 row_number() over(pattition by a order by b )
Posted 习惯简单
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql 实现 row_number() over(pattition by a order by b )相关的知识,希望对你有一定的参考价值。
SELECT prod_province,prod_cnode,prod_balance,rank FROM
(
SELECT b.prod_province,b.prod_cnode,b.prod_balance,@rownum:[email protected]+1 ,
IF(@pdept=b.prod_province,@rank:[email protected]+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 实现 row_number() over(pattition by a order by b )的主要内容,如果未能解决你的问题,请参考以下文章
mysql--实现oracle的row_number() over功能