计算sql server中列值的更改 [英] Count the changes in column value in sql server

查看:111
本文介绍了计算sql server中列值的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮我算一下这个

Ex:

计算sql server中列值的变化 - - - -

plz help me to count this
Ex:
Count the changes in column value in sql server - - - -

S.no        Gps
1              on
2              on
3              on
4              off
5              off
6              on
7              on
8              on
9              on
10              off

i want the result - 3

i want to count column value changes not value ... changement of on to off and off to on

推荐答案

Select count(*)
From table t1
join table t2 
on t2.id = t1.id + 1
where t2.Gps<> t1.Gps


我强烈建议您学习SQL的基础知识。

如果您知道这是一件非常简单的事情到目前为止我理解你的问题是非常基础的。



查看极简化的教程

SQL Tutorial [ ^ ]



我不会给出直接的解决方案,而是帮助你自己完成它。

你的解决方案的提示 -

SQL WHERE子句 [ ^ ]



如果您还没有找到解决方案,请回到此处分享您的想法你忘了分享这个问题了。



希望,你会为解决方案找到正确的方向:)
I strongly recommend you to learn the basics of SQL.
It's a very simple stuff to do if you know the very basics as far I understood your question.

Check this extremely simplified tutorials
SQL Tutorial[^]

I'll not give the direct solution, rather will help you to get it done yourself.
Hints for your solution-
SQL WHERE Clause[^]

If you still haven't find the solution, come back here and share what you think you forgot to share in the question.

Hope, you'll take the right direction to the solution :)


这篇关于计算sql server中列值的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆