求解释啊欲哭无泪看不懂 mysql实现分组后组内排序
row_number() OVER (PARTITION BY COL1 ORDER BY COL2) 表示根据COL1分组,在分组内部根据 COL2排序,而此函数计算的
值就表示每组内部排序后的顺序编号(组内连续的唯一的).  
是oracle的函数 我这里有个需求 就是把oracle转换成mysql语句
所以在网上找了一篇 解决方法 答案如下 可用到了用户变量 我晕了 不懂啊
求大虾们给解释啊
  drop table if exists heyf_t10;  
  create table heyf_t10 (empid int ,deptid int ,salary decimal(10,2) );
  insert into heyf_t10 values   
  (1,10,5500.00),  
  (2,10,4500.00),  
  (3,20,1900.00),  
  (4,20,4800.00),  
  (5,40,6500.00),  
  (6,40,14500.00),  
  (7,40,44500.00),  
  (8,50,6500.00),  
  (9,50,7500.00);  
  2. 确定需求: 根据部门来分组,显示各员工在部门里按薪水排名名次.  
  显示结果预期如下:  
  +-------+--------+----------+------+  
  | empid | deptid | salary | rank |  
  +-------+--------+----------+------+  
  | 1 | 10 | 5500.00 | 1 |   
  | 2 | 10 | 4500.00 | 2 |   
  | 4 | 20 | 4800.00 | 1 |   
  | 3 | 20 | 1900.00 | 2 |   
  | 7 | 40 | 44500.00 | 1 |   
  | 6 | 40 | 14500.00 | 2 |   
  | 5 | 40 | 6500.00 | 3 |   
  | 9 | 50 | 7500.00 | 1 |   
  | 8 | 50 | 6500.00 | 2 |   
-----------------------------------------------
做好的sql,SQL 实现  
  select empid,deptid,salary,rank from (  
         select heyf_tmp.empid,heyf_tmp.deptid,heyf_tmp.salary,@rownum:=@rownum+1 ,  
                if(@pdept=heyf_tmp.deptid,@rank:=@rank+1,@rank:=1) as rank,  
                @pdept:=heyf_tmp.deptid  
          from (   
                select empid,deptid,salary from heyf_t10 order by deptid asc ,salary desc   
          ) heyf_tmp ,
         (select @rownum :=0 , @pdept := null ,@rank:=0) a  
  ) result ;    
  结果演示  
  +-------+--------+----------+------+  
  | empid | deptid | salary | rank |  
  +-------+--------+----------+------+  
  | 1 | 10 | 5500.00 | 1 |   
  | 2 | 10 | 4500.00 | 2 |   
  | 4 | 20 | 4800.00 | 1 |   
  | 3 | 20 | 1900.00 | 2 |   
  | 7 | 40 | 44500.00 | 1 |   
  | 6 | 40 | 14500.00 | 2 |   
  | 5 | 40 | 6500.00 | 3 |   
  | 9 | 50 | 7500.00 | 1 |   
  | 8 | 50 | 6500.00 | 2 |   
  +-------+--------+----------+------+  
  9 rows in set (0.00 sec)  
-------------------------------------------------------
我的问题是
  select heyf_tmp.empid,heyf_tmp.deptid,heyf_tmp.salary,@rownum:=@rownum+1 ,  
                if(@pdept=heyf_tmp.deptid,@rank:=@rank+1,@rank:=1) as rank,  
                @pdept:=heyf_tmp.deptid  
这sql语句是先从右往左读 还是需哦那个左往右读啊??
是先执行的   @pdept:=heyf_tmp.deptid ,然后是if(@pdept=heyf_tmp.deptid,@rank:=@rank+1,@rank:=1) as rank,  
再后是@rownum:=@rownum+1 ,吗?我理解的对吗??
还有 if(@pdept=heyf_tmp.deptid,@rank:=@rank+1,@rank:=1) 这句是什么意思啊 第一个表达式表达的是
如果@pdept等于heyf_tmp.deptid,然后执行第二个表达式,否则执行第三个表达式吗??
------解决方案-------------------- 
探讨  2楼说什么我没看懂