赞
踩
先捋下变量的使用基本规则
在给一个变量赋值的同时使用这个值:
- 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
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。