我有一个可以关闭或打开的开关。我想跟踪按钮何时从关闭切换到打开或从打开切换到关闭。我在编写窗口函数以正确执行此操作时遇到问题。该按钮的默认起始行定位为 OFF(假)。
select
*,
row_number() OVER (PARTITION BY l.unique_identifier, l.button_status order by l.updated_at asc ) as idx
from
`data_log` l
where
l.unique_identifier = '123ABC'
order by
l.unique_identifier desc, l.updated_at asc
这是结果(我制作的最后一列是为了展示我希望达到的目标):
row_number 窗口函数的行为正常,但我正在寻找一种方法来按照其在所附图片的“预期结果”列中所写的方式进行操作。