本帖最后由 nuno_hh 于 2012-1-9 16:51 编辑
表TAB内有三个字段A、B、C、D,A为主键,具体数据如下
A
B
C
D
--------------------------------------------------
001 GGG 2011/11/20 09:10:00 1
002 BBB 2011/11/20 18:12:00 1
003 EEE 2011/11/21 01:10:00 1
004 DDD 2011/11/21 05:17:00 1
005 EEE 2011/11/21 20:10:00 0
006 FFF 2011/11/22 07:19:00 0
007 GGG 2011/11/22 10:10:00 0
008 HHH 2011/11/23 23:13:00 0
查询结果要求:从D=0中找是否有符合D=1、时间前后相差在24小时内、B相同的数据
上述数据中A=005这条数据符合
实在写不出,烦请各位大大们赐教!
create table TAB(
A varchar2(3),
B varchar2(3),
C date,
D char(1)
);
insert into TAB values ('001','GGG',to_date('2011/11/20 09:10:00', 'yyyy/mm/dd hh24:mi:ss'),'1');
insert into TAB values ('002','BBB',to_date('2011/11/20 18:12:00', 'yyyy/mm/dd hh24:mi:ss'),'1');
insert into TAB values ('003','EEE',to_date('2011/11/21 01:10:00', 'yyyy/mm/dd hh24:mi:ss'),'1');
insert into TAB values ('004','DDD',to_date('2011/11/21 05:17:00', 'yyyy/mm/dd hh24:mi:ss'),'1');
insert into TAB values ('005','EEE',to_date('2011/11/21 20:10:00', 'yyyy/mm/dd hh24:mi:ss'),'0');
insert into TAB values ('006','FFF',to_date('2011/11/22 07:19:00', 'yyyy/mm/dd hh24:mi:ss'),'0');
insert into TAB values ('007','GGG',to_date('2011/11/22 10:10:00', 'yyyy/mm/dd hh24:mi:ss'),'0');
insert into TAB values ('008','GGG',to_date('2011/11/23 23:13:00', 'yyyy/mm/dd hh24:mi:ss'),'0');
|