先捋下变量的使用基本规则
在给一个变量赋值的同时使用这个值:
set @rownum:=0;
select actor_id,@rownum:=@rownum+1 as rownum from actor limit 10;
使用自定义变量对结果进行排名:
set @film_num:=0;
select *,@film_num:=@film_num+1 as num from(
select actor_id,count(*) as cnt from film_actor GROUP BY actor_id ORDER BY cnt DESC limit 10)t
来源:CSDN
作者:学亮编程手记
链接:https://blog.csdn.net/a772304419/article/details/103952999