求语句
时间:2011-12-09
来源:互联网
表格如下:
id time num
a 9:00 22
a 10:00 2
a 11:00 20
a 12:00 9
a 13:00 18
.. . ......
a 16:00 15
b 9:00 22
b 10:00 2
b 11:00 20
b 12:00 9
b 13:00 18
.. . ......
b 16:00 14
c 9:00 11
.. . ......
.. . ......
.. . ......
.. . ......
每小时测量一次数据
a 和 b 在 9:00--15:00 期间的每一个数字完全相同,但是16:00以后就不相同了,
如何找出 9:00/ 16:00这两个时间点?
id time num
a 9:00 22
a 10:00 2
a 11:00 20
a 12:00 9
a 13:00 18
.. . ......
a 16:00 15
b 9:00 22
b 10:00 2
b 11:00 20
b 12:00 9
b 13:00 18
.. . ......
b 16:00 14
c 9:00 11
.. . ......
.. . ......
.. . ......
.. . ......
每小时测量一次数据
a 和 b 在 9:00--15:00 期间的每一个数字完全相同,但是16:00以后就不相同了,
如何找出 9:00/ 16:00这两个时间点?
作者: hongyuan20022003 发布时间: 2011-12-09
什么意思啊?
作者: fredrickhu 发布时间: 2011-12-09
SQL code
if object_id('tb') is not null drop table tb go create table tb ( id varchar(10), time datetime, num int ) go insert into tb select 'a','9:00',22 union all select 'a','10:00',2 union all select 'a','11:00',20 union all select 'a','12:00',9 union all select 'a','13:00',18 union all select 'a','14:00',15 union all select 'a','15:00',14 union all select 'a','16:00',12 union all select 'a','17:00',10 union all select 'a','18:00',9 union all select 'b','9:00',22 union all select 'b','10:00',2 union all select 'b','11:00',20 union all select 'b','12:00',9 union all select 'b','13:00',18 union all select 'b','14:00',15 union all select 'b','15:00',14 union all select 'b','16:00',10 union all select 'b','17:00',19 union all select 'b','18:00',30 go select convert(varchar(5),a1.time,108),convert(varchar(5),a2.time,108) from ( select top 1 t1.time from (select * from tb where id='a') t1 inner join (select * from tb where id='b') t2 on t1.time=t2.time and t1.num=t2.num order by time )a1 cross apply ( select top 1 t1.time from (select * from tb where id='a') t1 inner join (select * from tb where id='b') t2 on t1.time=t2.time and t1.num<>t2.num order by time )a2 /* ----- ----- 09:00 16:00 (1 行受影响) */
作者: pengxuan 发布时间: 2011-12-09
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28