原SQL:
SELECT *
FROM (select distinct v.parent_id parentVehId,
。。。。。
fvp.seat seat
from fc_vehicle v, fc_vehicle_parentfvp
where v.parent_id = fvp.parent_veh_id
minus
select distinct v.parent_id parentVehId,
。。。。。
fvp.seat seat
from fc_vehicle v, fc_vehicle_parent fvp,
pams_family_controller fc
where v.parent_id = fvp.parent_veh_id
andv.old_family_code = fc.family_code
and fc.flag = 1) A
order byA.price asc;这个SQL使用了Minus集合操作,distinct语句是不需要的,因为Minus本身就会去重。
等价SQL为:
SELECT *
FROM (select distinct v.parent_id parentVehId,
。。。。。。
fvp.seat seat
from fc_vehicle v, fc_vehicle_parentfvp
where v.parent_id = fvp.parent_veh_id
and not exists( select 1 from
pams_family_controller fc
where v.old_family_code = fc.family_code andfc.flag = 1) A
order byA.price asc;改写后的性能明显会比原来要好,具体好多少,要看数据量大小,数据量越大效果越明显!