|
造数据测试了一下,各种写法都差不多
create table xxxperson(idno int , validstate char(1),priority int,idtype int);
create index idx_xxxperson_idno on xxxperson(idno);
create table lcappnt(idno int,idtype int,contno varchar(30));
create index idx_lcappnt_contno on lcappnt(contno);
create table lcinsured(idno int,idtype int,contno varchar(30));
create index idx_lcinsured_contno on lcinsured(contno);
insert into xxxperson select i,i%7,i%3,i%3 from range(1000000)t(i);
insert into lcappnt select i,i%3,i+880037100000 from range(1000000)t(i);
insert into lcinsured select i,i%3,i+880037100000 from range(1000000)t(i);
--liu 1
select min(priority)
from XXXPERSON t
where
(
exists
(select 1
from LCAPPNT m
where m.idno = t.idno
and m.contno = '880037131628'
and t.validstate = '1'
)
or exists
(select 1
from LCINSURED n
where n.idno = t.idno
and n.contno = '880037131628'
and t.validstate = '2'
)
);
---newkid
select min(priority)
from XXXPERSON t
where (t.idno,t.validstate) in
(
select (m.idno,'1')
from LCAPPNT m
where m.contno = '880037131628'
union all
select (n.idno,'2')
from LCINSURED n
where n.contno = '880037131628'
);
--liu 2
select /*+ or_expand */min(priority)
from XXXPERSON t
where
( t.validstate = '1' and
exists
(select 1
from LCAPPNT m
where m.idno = t.idno
and m.contno = '880037131628'
)
)
or
( t.validstate = '2' and
exists
(select 1
from LCINSURED n
where n.idno = t.idno
and n.contno = '880037131628'
)
);
--liu 3
select min(priority)
from
(
select priority
from XXXPERSON t
where
exists
(select 1
from LCAPPNT m
where m.idno = t.idno
and m.contno = '880037131628'
and t.validstate = '1'
)
union all
select priority
from XXXPERSON t
where exists
(select 1
from LCINSURED n
where n.idno = t.idno
and n.contno = '880037131628'
and t.validstate = '2'
)
and ( exists
(select 1
from LCAPPNT m
where m.idno = t.idno
and m.contno = '880037131628'
and t.validstate = '1'
) is null
or not
exists
(select 1
from LCAPPNT m
where m.idno = t.idno
and m.contno = '880037131628'
and t.validstate = '1'
)
)
);
|
|