- 排序列号
select@rownum :=@rownum+1as rank,table.*from(select@rownum :=0) r ,F0126 tblae
- 分组序号
SELECT@r:=casewhen@type=a.company then@r+1else1endas rownum,@type:=a.company as company,
a.id as id,
a.salary as salary
from
F0126 a ,(select@r:=0,@type:='') b
select*from(SELECT@r:=casewhen@type=a.company then@r+1else1endas rownum,@type:=a.company as company,
a.id as id,
a.salary as salary
from
F0126 a ,(select@r:=0,@type:='') b )t where rownum in(select n from(select t.count,t.expr,if(t.expr ='奇数',ceiling(t.count/2),floor(t.count/2))as n from(selectcount(1)as count,if(mod(count(1),2)>=1,'奇数','偶数')as expr from(SELECT@r:=casewhen@type=a.company then@r+1else1endas rownum,@type:=a.company as company,
a.id as id,
a.salary as salary
from
F0126 a ,(select@r:=0,@type:='') b )t
groupby company)t)t)