我正在尝试创建一个查询,该查询根据另一列的运行最大值(例如本例中的分数)更新运行最大值列。
查询前的表
time-----score---------current max
1-----------5--------------null
2-----------6--------------null
3-----------3--------------null
4-----------4--------------null
5-----------5--------------null
6-----------7--------------null
7-----------8--------------null
查询后的表格
time-----score---------current max
1-----------5--------------5
2-----------6--------------6
3-----------3--------------6
4-----------4--------------6
5-----------5--------------6
6-----------7--------------7
7-----------8--------------8
如有任何建议,我们将不胜感激。
最佳答案
select @max := case when score > @max
then score
else @max
end as curr_max,
time,
score
from your_table, (select @max := 0) m
关于MySQL 更新运行最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20883115/