3,492
社区成员
发帖
与我相关
我的任务
分享
SQL> with tb as
2 (
3 select '12' rq,'09:00' sj,'013' bh,'ZA' st,'TA' en from dual union all
4 select '12','10:00','013','TA','XA' from dual union all
5 select '12','09:30','020','ZA','YA' from dual union all
6 select '12','10:10','027','ZA','UA' from dual union all
7 select '12','11:20','034','SA','RA' from dual union all
8 select '12','13:10','042','XA','UA' from dual union all
9 select '12','14:20','042','ZA','RA' from dual
10 )
11 select * from tb where rq='12' and st='ZA'
12 union
13 select * from tb a
14 where exists(select 1 from tb b where a.bh=b.bh and a.sj>b.sj and b.rq='12' and b.st='ZA')
15 /
RQ SJ BH ST EN
-- ----- --- -- --
12 09:00 013 ZA TA
12 09:30 020 ZA YA
12 10:00 013 TA XA
12 10:10 027 ZA UA
12 14:20 042 ZA RA
select * from test
where 日期='12' and 始发='ZA'
union all
select * from test a
where exists(select 1 from test b where b.日期='12' and b.始发='ZA' and a.编号=b.编号 and a.始发!=b.始发 and a.到达!=b.到达 and a.时间>b.时间)
and a.日期='12'
select * from TEST
where 日期 = '12' --就算字符型
start with 始发 = 'ZA'
connect by 到达 = prior 始发 and 编号 = prior 编号 and 时间 > prior 时间
select * from test
where 日期='12' and 始发='ZA'
union all
select * from test a
where exists(select 1 from test b where b.日期='12' and b.始发='ZA' and a.编号=b.编号 and a.始发!=b.始发 and a.到达!=b.到达 and a.时间>b.时间)
呵呵,忘记了时间限定.
select * from test a where not exists(select 1 from test b where a.编号=b.编号 and a.时间>b.时间) and a.始发='ZA' and a.日期='12'
select * from test
where 日期='12' and 始发='ZA'
union all
select * from test a
where exists(select 1 from test b where b.日期='12' and b.始发='ZA' and a.编号=b.编号 and a.始发!=b.始发 and a.到达!=b.到达)