计算表列中的值更改

dou*_*sin 3 sql sqlite

考虑一个排序表(根据id)。如何计算“值”列中值的变化次数?在以下示例中,更改数量为3(10到20、20到10、10到30)。谢谢

id值
 1 10
 2 10
 3 20
 4 20
 5 10
 6 30
 7 30

Cha*_*ana 5

如果id是连续的且没有间隙...

Select count(*)
From table t1
   join table t2 
       on t2.id = t1.id + 1
where t2.value <> t1.value
Run Code Online (Sandbox Code Playgroud)

其他...

Select count(*)
From table t1
   join table t2 
       on t2.id = (Select min(id)
                   From table 
                   where id > t1.id)
where t2.value <> t1.value
Run Code Online (Sandbox Code Playgroud)