mysql变量种类:全局变量/会话变量/局部变量/自定义变量
参考:https://www.cnblogs.com/genialx/p/5932558.html
自定义变量能让sql实现更复杂的功能
例子:LeetCode178 https://leetcode-cn.com/problems/rank-scores/ 分数排名实现dense_rank()功能
select
s.Score, a.r as 'Rank'
from Scores s
join (select Score, @row:=@row+1 as r from
(select distinct Score from Scores order by Score desc) c,
(select @row:=0) t) a
on s.Score = a.Score
order by s.Score desc
参考:https://www.cnblogs.com/guaidaodark/p/6037040.html 写的比较全了