Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我有一张这样的表:
|id|val| |--|---| |1 |a | |2 |b | |3 |b | |4 |c | |5 |b |
是否有一种纯粹的 MySQL 方法来生成以下结果:
|id|val| |--|---| |1 |a | |2 |b | |4 |c | |5 |b |
通常这是使用滞后窗口函数完成的,但 MySQL 不支持这一点。然而,有一个使用变量的解决方法:
SET @val=null; select id, curr_val as val from ( select id, @val prev_val, @val:=val curr_val from tbl ) where curr_val != prev_val;