日期:2014-05-18  浏览次数:20364 次

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

數據庫表裡有如下數據:
        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相同,但是時間有交替或重復資料呢?

------解决方案--------------------
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))
------解决方案--------------------
select * from tb where mno in
(select mno
from tb
group by mno
having count(*)> 1
)
------解决方案--------------------
我觉得你这个问题是考虑时间是否交叉的问题。我做过IP段的判断,和你这个类似。我是在录入的时候,做了个表,存放重要不能雷同字段,并将IP范围转成了两个数字,然后判断的。时间也能转成这样。希望对你有帮助