sql改写

[复制链接]
查看11 | 回复2 | 2015-7-16 14:18:24 | 显示全部楼层 |阅读模式
本帖最后由 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')

回复

使用道具 举报

千问 | 2015-7-16 14:18:24 | 显示全部楼层
(+)是oracle的写法,改成left join
回复

使用道具 举报

千问 | 2015-7-16 14:18:24 | 显示全部楼层
NOT EXISTS确实可以改成外连接+IS NULL。
程序看不出什么问题,楼主自己要多测试。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行