本帖最后由 alibull 于 2015-12-10 19:06 编辑
一个比较变态的sql,其中not exists(exists..)已无从下手,请教,谢谢!
select count(distinct a.id)
from ticket_return a, ticket_returnrecord trr
where 1 = 1
and trr.tfid = a.id
and trr.hkgs not in ('ZH')
and not exists
(select 1
from ticket_all tt, ticket_returnrecord tr
where tt.tkno = tr.tkno
and tr.tfid = a.id
and exists
(select 1
from ticket_hdb
where tkno = tt.tkno
and (tfmxid is null or tfmxidtr.id)))
and a.tp_datetime_date >=
to_date('2015-12-09 00:00:00', 'yyyy-mm-dd hh24:mi:ss')
and a.tp_datetime_datetr.id))tt1
where 1 = 1
and trr.tfid = a.id
and a.id =tt1.tfid(+)
and trr.hkgs not in ('ZH')
and tt1.tfid isnull
and a.tp_datetime_date >=
to_date('2015-12-09 00:00:00', 'yyyy-mm-dd hh24:mi:ss')
and a.tp_datetime_date <=
to_date('2015-12-10 00:00:00', 'yyyy-mm-dd hh24:mi:ss')