求解抓取時間交替或重復資料的SQL語句

wupingjiazy 2007-05-04 10:54:06

數據庫表裡有如下數據:
A_no mno s_time e_time
200701001 000001 2007/01/01 14:20 2007/01/01 18:00
200701002 000001 2007/01/01 16:20 2007/01/01 20:00


其它數據省略.

請問我抓取mno相同,但是時間有交替或重復資料呢?
...全文
229 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wupingjiazy 2007-05-04
  • 打赏
  • 举报
回复
OK。觖決了。給分.
gahade 2007-05-04
  • 打赏
  • 举报
回复
select a.*
from 表 a,表 b
where a.mno=b.mno and a.s_time>=b.e_time and a.s_time<=b.e_time
zhoulin777 2007-05-04
  • 打赏
  • 举报
回复
我觉得你这个问题是考虑时间是否交叉的问题。我做过IP段的判断,和你这个类似。我是在录入的时候,做了个表,存放重要不能雷同字段,并将IP范围转成了两个数字,然后判断的。时间也能转成这样。希望对你有帮助
Andy__Huang 2007-05-04
  • 打赏
  • 举报
回复
select * from tb where mno in
(select mno
from tb
group by mno
having count(*)>1
)
wupingjiazy 2007-05-04
  • 打赏
  • 举报
回复
gahade(与君共勉) :

我隻要抓出同一個mno,但兩個時間段有重復或重壘的資料。
按你的SQL語句,時間段沒有重復或重壘的資料也會被抓出。

時間段是指 s_time 至 e_time 之間


2007/01/01 14:20 2007/01/01 18:00
2007/01/01 16:20 2007/01/01 20:00

這兩個時間段就算有重壘
gahade 2007-05-04
  • 打赏
  • 举报
回复
select * from 表 a
where exists(select 1 from 表 b where a.mno=b.mno and (a.s_time<>b.s_time or a.e_time<>b.e_time))

27,581

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧