try:
Select aa.* from table1 aa
join (select sj from table1 where b is null) bb
on abs(datediff(minute,aa.sj,bb.sj)) <= 5
where aa.b is not null
Select aa.* from table1 aa
join (select sj from table1 where b is null) bb
on abs(datediff(minute,aa.sj,bb.sj)) <= 5
where aa.b is not null
解决方案 »
- 请问按记录和字段内容循环的问题
- 急! ! ! !急! ! ! !急! ! ! !求一SQL语句写法
- 刚刚完成的原创两篇文章,一篇关于全文索引,一篇关于变量赋值的探讨。欢迎阅读。
- 我刚看SQLSERVER,请问它与SQL SERVER AGENT有什么关系啊?
- sql分类汇总排序问题
- 不知有沒有答案---試試看看
- 怎么用ado运行带go的sql脚本,各位大哥救命呀,在线等待
- 在vfp中,么样一搞就出现什么‘致命错误’???分数好说。
- 为什么我的SQL SERVER2000连CSTR函数都不认
- 惊世之作!VD3.0!(Visual DBTOOLS 3.0)
- 如何用SQL语句删除数据库中的重复行?
- 一个关于sum的问题!
create table table1 (sj datetime,a char(10),b char(10))
insert table1 select '2003-10-20 9:10:11','aaaa','b'
Union all select '2003-10-20 9:11:11','xxxx',null
Union all select '2003-10-20 9:11:30','xxxr',null
Union all select '2003-10-20 9:11:50','xxxr','b'
Union all select '2003-10-20 9:12:11','xxxr','bb'
Union all select '2003-10-20 9:34:11','xxxr',null
Union all select '2003-10-20 9:35:11','xxxr','b'
Union all select '2003-10-20 9:35:45','xxxr','b'
Union all select '2003-10-20 9:36:11','xxxr',null
Union all select '2003-10-20 10:20:45','xxxr','b'
Union all select '2003-10-20 10:20:45','xxxr','b'Select distinct aa.* from table1 aa
join (select sj from table1 where b is null) bb
on abs(datediff(minute,aa.sj,bb.sj)) <= 5
where aa.b is not null
sj a b
------------------------------------------------------ ---------- ----------
2003-10-20 09:10:11.000 aaaa b
2003-10-20 09:11:50.000 xxxr b
2003-10-20 09:12:11.000 xxxr bb
2003-10-20 09:35:11.000 xxxr b
2003-10-20 09:35:45.000 xxxr b (所影响的行数为 5 行)
(select sj from table1 where b is null) B
on abs(datediff(minute,A.sj,B.sj)) <= 5
where A.b is not null