用sql查询如下要求的数据如何写代码
时间:2011-12-05
来源:互联网
有如下数据,C列为时间单位为秒,现想找出相差三秒中内A中同个数据出现三次的记录数。可能A列中相同的数据很多,但是只要C列中数值相差三秒钟内包含三秒的情况下,A列相同数据出现三次,将这三次的数据找出来即可,之前我也发帖过,但是问题弄错,谢谢大家
A B C(秒)
123 222 23
223 221 23
223 256 26
123 22 27
123 126 29
223 225 558
223 256 25
123 223 30
通过查找结果为:
A B C(秒)
223 221 23
223 256 26
123 22 27
123 126 29
223 256 25
123 223 30
请问sql查询如何书写,谢谢大家
A B C(秒)
123 222 23
223 221 23
223 256 26
123 22 27
123 126 29
223 225 558
223 256 25
123 223 30
通过查找结果为:
A B C(秒)
223 221 23
223 256 26
123 22 27
123 126 29
223 256 25
123 223 30
请问sql查询如何书写,谢谢大家
作者: weiliansanyu 发布时间: 2011-12-05
SQL code
create table tb(A int,B int,C int) insert into tb select 123,222,23 insert into tb select 223,221,23 insert into tb select 223,256,26 insert into tb select 123,22,27 insert into tb select 123,126,29 insert into tb select 223,225,558 insert into tb select 223,256,25 insert into tb select 123,223,30 go select a.* from tb a inner join( select * from tb a where exists(select 1 from tb where a=a.a and c<>a.c and c-a.c between 1 and 3) and exists(select 1 from tb where a=a.a and c<>a.c and a.c-c between 1 and 3) )b on a.a=b.a and abs(a.c-b.c)<=3 /* A B C ----------- ----------- ----------- 123 22 27 123 126 29 123 223 30 223 221 23 223 256 26 223 256 25 (6 行受影响) */ go drop table tb
作者: qianjin036a 发布时间: 2011-12-05
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28